|
From: | Richard Frith-Macdonald |
Subject: | Re: Exception handling with NSURL |
Date: | Thu, 06 Dec 2007 09:32:56 +0000 |
User-agent: | GNUMail (Version 1.2.0) |
Hi all, I'm trying to verify a string is a valid URL with the following : - (void)controlTextDidChange:(NSNotification *)notification { NS_DURING { NSURL *storeUrl = [NSURL URLWithString:[url stringValue]]; [ok setEnabled:(storeUrl != nil)]; } NS_HANDLER { NSLog([localException name]); [ok setEnabled:NO]; } NS_ENDHANDLER } When I enter an URL of the form http://user:address@hidden, an exception israised (see below) when starting to enter the password because NSURL isexpecting a numeric port (as in http://host:port). The thing is, the exception isn't catched by NS_HANDLER (NSLog is never called) and the application coredumps when I enter another caracter. <NSException: 0x8357318> NAME:NSGenericException REASON:illegalcharacter in port part
<snip>
Am I doing something wrong ?
My guess is that you are misinterpreting what's happening.Probably the reason the NSLog() in the exception handler is not called is because the handler is not called because the exception is not ocurring in this piece of code. The exception message 'illegal character in port part' does not correspond to a URL for the form 'http://user:address@hidden' because such a URL has no port part, so it's presumably being raised because some otyher URL used elsewhere in the program has a port part containing an illegal character.
[Prev in Thread] | Current Thread | [Next in Thread] |