title: NSURL URLWithString: raises exception
body: <p>In short, <code>[NSURL URLWithString:]</code> appears to be raising an exception. According to the documentation "If the string was malformed, returns nil." There is no mention of an exception being raised under any circumstance. In addition to this, I am both encoding the URL and checking for <code>nil</code> before converting the string to a URL.</p>
  
  <p>Can anyone offer any advice as to which exception it could be or what other error checking I should be doing before converting the URL?</p>
  
  <p>In case you're interested in the details, the calling code looks like this:</p>
  
  <pre><code>NSString* tmpText = [newUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  if (tmpText == nil) {
      // error handling
  }
  else {
      NSURL* tmpURL = [NSURL URLWithString:tmpText];
  </code></pre>
  
  <p>And this is a section from the crash report download from iTunes Connect:</p>
  
  <pre><code>8   libobjc.A.dylib                 0x300c1f84 objc_exception_throw
  9   CoreFoundation                  0x3029a598 +[NSException raise:format:arguments:]
  10  CoreFoundation                  0x3029a538 +[NSException raise:format:]
  11  Foundation                      0x30696dde -[NSURL initWithString:relativeToURL:]
  12  Foundation                      0x30696cd8 +[NSURL URLWithString:relativeToURL:]
  13  Foundation                      0x30696cae +[NSURL URLWithString:]
  14  Yummy                           0x000146ca -[DeliciousPostCell setUrl:] + 46
  </code></pre>
  
  <p>It seems that the URL was in a "bad" format somehow but that should really be returning a <code>nil</code> not an exception.</p>
  
  <p>I have never seen the exception being raised myself so I can't use XCode to trap the code and see what's happening. And the user(s) that experienced the problem never contacted me directly so I can't ask for more details. Any suggestions greatly appreciated.</p>
  
  <p><em>Update (14/7/2009)</em>: Seems like such a hack, but I added an exception block around the suspect line. I also raised a Radar bug report (#7031551) suggesting that the code should match the documentation.</p>