• 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
Proper way to throw an exception in an iOS application...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proper way to throw an exception in an iOS application...


  • Subject: Proper way to throw an exception in an iOS application...
  • From: Brian Lambert <email@hidden>
  • Date: Sat, 17 Mar 2012 13:19:39 -0700

Happy Coding Saturday!

Regarding iOS / OS X exception throwing.

One camp says to use:

    [NSException raise:NSInvalidArgumentException format:@"pageIndex is out of range"];

Which I was first exposed to and have been using.

This doesn't seem to be ideal, though, because the compiler doesn't recognize that this represents a throw and sometimes you wind up with the awkward: "Control may reach end of non-void function" case and have to code something like:

    [NSException raise:NSInternalInconsistencyException format:@"Mumblefart can't be somethingorothered"];
    return nil; // Can't actually get here. Awkward Code...

It would seem, then, that using @throw would be superior:

    @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"pageIndex is out of range" userInfo:nil];

But it doesn't seem to be highly used in code I'm reading.

I'm leaning towards switching to @throw.

How do the awesomest engineers do this? Your thoughts?

Best,

Brian

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Proper way to throw an exception in an iOS application...
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: Utter disbelief
  • Next by Date: Re: Proper way to throw an exception in an iOS application...
  • Previous by thread: Re: Re-signing an archive
  • Next by thread: Re: Proper way to throw an exception in an iOS application...
  • Index(es):
    • Date
    • Thread