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

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


  • Subject: Re: Proper way to throw an exception in an iOS application...
  • From: Luther Baker <email@hidden>
  • Date: Sun, 18 Mar 2012 00:28:36 -0500

Might be a question for the folks over at email@hidden or email@hidden

-Luther


On Sat, Mar 17, 2012 at 4:43 PM, Quincey Morris <email@hidden> wrote:
On Mar 17, 2012, at 14:13 , Brian Lambert wrote:

NSAssert sounds perfect for this.

On Sat, Mar 17, 2012 at 1:41 PM, Fritz Anderson <email@hidden> wrote:

[…] and they become no-ops when you define NS_BLOCK_ASSERTIONS in your release build. Because assertions encapsulate the fail branch, you'd have to provide a return value. I wouldn't lose sleep over it.

I'm not sure what Fritz was saying, but there's no need to provide a return statement after a NSAssert (at least, not with clang, and I don't recall needing it in GCC either).

Also, it's easy enough to use NSAssert's source code (Command-click on a use of it to go to the header file that defines it) as a model for your own version of the macro that doesn't need a test condition. I think that looks cleaner in cases where you've already tested for the error with an 'if', rather than writing 'NSAssert (NO, @…")' -- and I can never quite get used to reversing the test to use as the first parameter directly.

I have to admit, I happen to prefer to leave the asserts enabled in release builds. If the exceptional condition should arise, and it's one of those hard-to-reproduce things, the message in a customer's Console log is often the only clue to what really happened.

The downside, of course, is that such exceptions will typically be caught and ignored by the frameworks, which means that the app will misbehave -- though if the condition arises, it's probably going to misbehave anyway. Also, customers are not aware of the existence of the messages until you have them go look.

I also have to admit that at one point I tried -- and distinctly failed -- to force the (released) app to terminate on any uncaught-by-my-code exception. I never figured out what I was doing wrong, but I expect I'll learn someday.



 _______________________________________________
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


 _______________________________________________
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

References: 
 >Proper way to throw an exception in an iOS application... (From: Brian Lambert <email@hidden>)
 >Re: Proper way to throw an exception in an iOS application... (From: Fritz Anderson <email@hidden>)
 >Re: Proper way to throw an exception in an iOS application... (From: Brian Lambert <email@hidden>)
 >Re: Proper way to throw an exception in an iOS application... (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Proper way to throw an exception in an iOS application...
  • Next by Date: Re: Proper way to throw an exception in an iOS application...
  • Previous by thread: Re: Proper way to throw an exception in an iOS application...
  • Next by thread: Re: Proper way to throw an exception in an iOS application...
  • Index(es):
    • Date
    • Thread