Re: Are there macros for exception-based error checking?
Re: Are there macros for exception-based error checking?
- Subject: Re: Are there macros for exception-based error checking?
- From: Shawn Erickson <email@hidden>
- Date: Tue, 3 May 2005 16:24:07 -0700
On May 2, 2005, at 5:25 PM, Larry Gerndt wrote:
In CodeWarrior/PowerPlant, I was used to writing code like this:
try {
ThrowIfOSStatus_( SomeFunctionThatReturnsOSStatus() );
ThrowIfOSStatus_( SomeFunctionThatReturnsOSStatus() );
ThrowIfOSStatus_( SomeFunctionThatReturnsOSStatus() );
} catch(LException &inErr) {
handling code
}
ThrowIfOSStatus_ is a macro which will throw an exception if an
error status is returned. I've grown to love this kind of thing
because it makes code easier to read than something like this:
Note that since Mac OS X 10.3 you have the ability use things like
the following in Objective-C (if you enable objective-c exceptions in
the compiler settings)...
@try {
...
@throw ...;
...
@synchronize(..) { << basically a recursive mutex
...
@throw ...;
...
return ...;
}
...
} @catch(...) {
} @catch(...) {
} @finally {
}
...
return ...;
Before 10.3 you would use macros to do the same (with a few
additional quirks and work)...
NS_DURING
...
if (someError)
[anException raise];
...
NS_HANDLER
if ([[localException name] isEqualToString:MyAppException]) {
NSRunAlertPanel(@"Error Panel", @"%@", @"OK", nil, nil,
localException);
}
[localException raise]; /* Re-raise the exception. */
NS_ENDHANDLER
For more information...
<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/
LanguageOverview/chapter_3_section_9.html>
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden