• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Are there macros for exception-based error checking?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Are there macros for exception-based error checking?
      • From: Shawn Erickson <email@hidden>
    • Re: Are there macros for exception-based error checking?
      • From: Annard Brouwer <email@hidden>
  • Prev by Date: [Moderator] Re: Tiger documentation update
  • Next by Date: Re: OutlineEdit example (outlineView:heightOfRowByItem:)
  • Previous by thread: Re: Is this a bug in Tiger's NSBitmapImageRep?
  • Next by thread: Re: Are there macros for exception-based error checking?
  • Index(es):
    • Date
    • Thread