Re: exception in init
Re: exception in init
- Subject: Re: exception in init
- From: Corbin Dunn <email@hidden>
- Date: Wed, 04 Apr 2012 09:19:07 -0700
The general rule is:
1. If it is considered a programming error, raise an exception (or assert -- it is the same)
2. If it is normal code flow, then don't log or do anything strange.
However, in general, it is troublesome to have init's return nil.
corbin
On Apr 4, 2012, at 4:38 AM, Ariel Feinerman <email@hidden> wrote:
> Hi,
>
> I think the question was asked and answered but I cannot see a clearance
> what is the right way to write init in the cases the arguments are nil or
> wrong?
> Returning a nil or raising an exception?
>
> - (id) initWithURL: (NSURL *) url {
>
>
> if ((self = [super init])) {
>
> if (!url) {
>
> // ?
>
> }
>
> if (![url isFileURL]) {
>
> // ?
>
> }
>
> }
>
> return self;
>
> }
>
> I can frequently see the following in init
>
> NSAssert(url, @"url may not be nil", );
>
> --
> best regards
> Ariel
> _______________________________________________
>
> 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
_______________________________________________
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