Are there macros for exception-based error checking?
Are there macros for exception-based error checking?
- Subject: Are there macros for exception-based error checking?
- From: Larry Gerndt <email@hidden>
- Date: Mon, 2 May 2005 17:25:20 -0700
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:
OSStatus err;
err = SomeCarbonFunctionThatReturnsOSStatus()
if (err==noErr)
err = SomeCarbonFunctionThatReturnsOSStatus()
if (err==noErr)
err = SomeCarbonFunctionThatReturnsOSStatus()
I was surprised that I could not find such macros in NSFoundation or
somewhere in Cocoa, nor have I yet seen something like in anyone else's
Cocoa code. Is there some good reason why this is so, or have I missed
something?
P.S. My solution for now was to use the NSCAssert in a macro:
#define ThrowIfOSStatus_(condition) NSCAssert(noErr==condition, @"")
Is this a good approach?
--
Larry Gerndt
AIM Handle: SonOfTheSonOfMan
Let the truth be told though the heavens fall -- James Garrison
_______________________________________________
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