title: How to catch an error during an Objective-C method call that takes no NSError argument?
body: <p>I understand that some methods in Objective-C take a pointer to an <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/index.html" rel="nofollow"><code>NSError</code></a> object to be populated in the case where an error occurs.</p>
  
  <p>But how to trap for an error occurring in an Objective-C method that does <em>not</em> take any such error argument? </p>
  
  <p>For example, the <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/canOpenURL:" rel="nofollow"><code>canOpenURL</code></a> method:</p>
  
  <pre><code>BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
  </code></pre>
  
  <p>…prints on the console:</p>
  
  <pre><code>-canOpenURL: failed for URL: "bogus://example/" - error: "(null)"
  </code></pre>
  
  <p>This is <em>not</em> because of the iOS 9 restriction on calling <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/canOpenURL:" rel="nofollow"><code>canOpenURL</code></a> requiring a declaration of custom URL schemes to be tested in the plist as <a href="http://interactivelogic.net/wp/2016/03/how-to-query-custom-url-schemes-in-ios-9-hint-its-different-now/" rel="nofollow">discussed in this blog post</a>. In this case I did indeed declare the scheme. If the scheme were not declared in the plist, the error message would be a sentence rather than the word <code>null</code> you see above.</p>
  
  <p>So this mysterious error seen above is being reported when (a) the custom URL scheme has been declared in a <code>LSApplicationQueriesSchemes</code> string array in the plist AND (b) there is no app on the physical device willing to handle that schema (schema is 'bogus' in this example).</p>
  
  <p>The <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/canOpenURL:" rel="nofollow"><code>canOpenURL</code></a> method takes no argument for a <a href="https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/index.html" rel="nofollow"><code>NSError</code></a> to be populated. So how can I trap for this error happening, and avoid having the class print messages into my console or log?</p>