Object-C provides a Java/C ++-style error handling model. When the-fobjc-exceptions switch (GCC> 3.3) is used, it can work, however, this feature is only available in Versions later than OS X v10.3.
The principle of using error capture is similar to that of other languages: you cannot use it as a condition for normal stream processing. Instead, you can use it as an "unexpected"
You can use multiple @ catch blocks to capture different error types.
Cup * Cup = [[cup alloc] init];
@ Try {
[Cup fill];
}
@ Catch (nsexception * exception ){
Nslog (@ "Main: Caught % @: % @", [Exception name], [Exception reason]);
}
@ Finally {
[Cup release];
}
An exception class can be implemented by yourself, but it is generally nsexception or its subclass.
For more information about error handling, see:
Http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40001806