Popular Tags

Who's online

There are currently 0 users and 10 guests online.

User login

Error handling is done differently in Objective-C that in other languages. Unlike in Java, exceptions are not used willy-nilly for any unexpected condition. The runtime generates exceptions for truly problematic occurrences, but it's generally considered bad form to use exceptions for your own code. It's just not “the way”, so to speak.

There are several acceptable alternatives, although the best choice often depends on your design.

In any case, read the documentation for NSException and NSError before forging ahead.

Handling Exceptions

If you want to handle exceptions that are raised (whether by the runtime or other code) use this format:

@try {
   // code that might raise 1+ exceptions
}
@catch (NSException *exc) {
   // code for handling raised exception(s)
}
@finally {
   // code to cleanup stuff from the @try
}

Using NSError Instead of Exceptions

There are a few good articles on the Cocoa Is My Girlfriend blog:

No votes yet

Search

UPDATES

The site has recently been updated. You may notice some of the following issues:

  • Some URLs no longer work. Please use the search box.
  • File uploads should now be working. If you experience problems, please contact us.