O'Reilly logo

Objective-C Fundamentals by Collin Ruffenach, Johannes Fahrenkrug, Christopher K. Fairbairn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Error and exception handling

 

This chapter covers
  • Dealing with NSError
  • Creating your own NSError objects
  • When and when not to use exceptions

 

Things go wrong. That’s no surprise. And things go wrong in the software you build. Maybe the server that hosts the API you want to talk to isn’t reachable, or the XML file you need to parse is corrupt, or the file you want to open doesn’t exist. You need to prepare for such cases and handle them gracefully, which means not crashing and giving the user an appropriate message.

Cocoa Touch and Objective-C offer two ways of dealing with errors: NSError and exceptions. NSError is the preferred and advisable way to deal with expected errors (like an unreachable host). Exceptions are meant ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required