Re: Professional Error Handling
Re: Professional Error Handling
- Subject: Re: Professional Error Handling
- From: Jens Alfke <email@hidden>
- Date: Thu, 22 Oct 2009 16:52:35 -0700
On Oct 22, 2009, at 4:40 PM, Squ Aire wrote:
And then of course return NO or nil from the method. Is this how the
professionals would do it?
Basically, although I have a utility function that does most of the
work, so I don't have to dump ten lines of boilerplate into my code
every time there's a possible error.
The first, and only obvious, problem I can see with this is that I'm
putting a magic number 43 in there. I determine this magic number by
doing a manual project find for "GreatApp.ErrorDomain" and adding
one to the greatest error number that already exists.
This is what C's 'enum' is for. Create a header file, like "Errors.h"
and define all your error codes in it:
enum {
kErrFoo = 1,
kErrBar,
kErrZog,
kErrLOL
};
Then just #import this header in any source file where you need to
create an error, and refer to the error code by its constant.
When you need to define a new error code, just add it to the end of
the list.
The second problem is of the error domain string. To me it currently
feels like good enough to just have one error domain for the whole
app since the app is not huge. The only question is where on earth I
would put a constant for that string.
It goes in this header too :)
—Jens
_______________________________________________
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