• 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: Error and Exception Handling: When to use
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Error and Exception Handling: When to use


  • Subject: RE: Error and Exception Handling: When to use
  • From: Nelson Santos <email@hidden>
  • Date: Tue, 12 Jun 2007 13:05:18 -0400

Hi Klaus,

Thanks for the links. I have read these articles in the past but they mostly discuss how to implement something, rather than when. In any case, I decided to thumb through them again, and I found the following paragraph in the Error Handling Programming Guide For Cocoa that either I forgot or never read before:

----------------

Exceptions (represented by NSException objects) are for programming errors, such as an array index that is out of bounds or an invalid method argument. User-level errors (represented by NSError objects) are for runtime errors, such as when a file cannot be found or a string in a certain encoding cannot be read. Conditions giving rise to exceptions are due to programming errors; you should deal with these errors before you ship a product. Runtime errors can alway occur, and you should communicate these (via NSError objects) to the user in as much detail as they require.

Although exceptions should ideally be taken care of before deployment, a shipped application can still experience exceptions as a result of some truly exceptional situation such as “out of memory” or “boot volume not available.” It is best to allow the highest level of the application—NSApp itself—to deal with these situations.

----------------



So according to this, I should ALWAYS use NSException objects in all of my methods to verify arguments and other programming related errors (assuming there is nothing I can do to recover from the invalid arguments). And I should always use NSError objects for runtime (i.e. user) related errors.

So, if I understand correctly, I should use these two classes to catch as many problems as I can before shipping a finished product. Any exceptions that I throw and forget to catch during my testing phase will ultimately be caught by NSApp and reported to the user, and cause a shutdown of the application. Is that right?

Does anyone else follow this mantra? Does anyone have an issues with this approach?


Nelson


On 12-Jun-07, at 11:59 AM, Klaus Backert wrote:

Hi, Nelson,

Am 12.06.2007 um 16:16 schrieb Nelson Santos:
<snip>

you should read the NSException and the NSError class references. There you will find links to the companion guides "Exception Programming Topics in Cocoa" and "Error Handling Programming Guide in Cocoa". These documents describe Apple's policy of what exceptions and errors are and where and how they should be used. This differs, I think, from what you were told in some other posts (sorry).

Cheers
Klaus

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Error and Exception Handling: When to use
      • From: Uli Kusterer <email@hidden>
References: 
 >RE: error handling (From: "Nelson Santos" <email@hidden>)
 >Re: error handling (From: Klaus Backert <email@hidden>)

  • Prev by Date: Re: dynamically sized text container
  • Next by Date: performance of encoding an array of structs
  • Previous by thread: Re: error handling
  • Next by thread: Re: Error and Exception Handling: When to use
  • Index(es):
    • Date
    • Thread