Chapter 14. Exception Handling

Exception handling in Objective-C is almost identical in capacity with that in Java. Objective-C is, naturally, more casual about exceptions and makes none of the demands that Java does. You can design and write code using Objective-C exceptions exactly as you would in Java, completely ignore them, or settle somewhere in between. This chapter will briefly compare the similarities between Objective-C and Java exception handling—of which there are many—and then explain some of the subtle differences. Later sections will discuss assertions and alternatives to exceptions.

Using Exceptions

Creating, throwing, and catching exceptions are virtually identical in Objective-C and Java. Listing 14-1 shows some simple exception ...

Get Learn Objective-C for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.