8.7. Exceptions
8.7 Exceptions
GNU Objective-C provides exception support built into the language, as in the following example:
@try { ... @throw expr; ... } @catch (AnObjCClass *exc) { ... @throw expr; ... @throw; ... } @catch (AnotherClass *exc) { ... } @catch (id allOthers) { ... } @finally { ... @throw expr; ... }
The @throw
statement may appear anywhere in an Objective-C or Objective-C++ program; when used inside of a @catch
block, the @throw
may appear without an argument (as shown above), in which case the object caught by the @catch
will be rethrown.
Note that only (pointers to) Objective-C objects may be thrown and caught using this scheme. When an object is thrown, it will be caught by the nearest @catch
clause capable of handling objects of that type, analogously to how catch
blocks work i