Re: -(id)init methods, NSExceptions, and returning nil
Re: -(id)init methods, NSExceptions, and returning nil
- Subject: Re: -(id)init methods, NSExceptions, and returning nil
- From: Ken Thomases <email@hidden>
- Date: Mon, 27 Jun 2011 09:51:47 -0500
On 27-Jun-2011, at 9:22 PM, William Squires wrote:
> 2) Isn't the prevailing paradigm to raise an NSException if something goes wrong?
No. In Cocoa, exceptions are used to indicate programmer error, not runtime failure. In general, Cocoa isn't exception safe, so if an exception occurs, your app should do its best to gracefully shut down, save data (without overwriting known-good data, since you can't be sure the app is in a good state), with an explanation to the user.
> or is 'init'ing a special case?
-init isn't special with respect to the above convention regarding exceptions, but it does have its own conventions. Among those is that failure is indicated by returning nil.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden