Objective C – Exception handling In iPhone
The exception handling mechanisms available to Objective-C programs are effective ways of dealing with exceptional conditions. They decouple the detection and handling of these conditions and automate the propagation of the exception from the point of detection to the point of handling. As a result, your code can be much cleaner, easier to write correctly, and easier to maintain.
An exception is a special condition, but interrupts normal flow of execution objective c has four exception compiler directives. They are.
try black holds code that can potentially throw an exception which is enclosed in a try black.
Scan f ( “%d”, &x); Int y = 2/x;
A catch block contains exception handling logic for exception throw in a try block. We can have multiple catch block for single try block.
@ catch (NS argument exception * aex)
@catch(NS exception * ex)
This block is optional and it contains a code for declaration of resources .
NS exception classes the base class for all the exception related classes.
By using throws, we can rise over own exception.