Exception handling syntax: Difference between revisions

Content deleted Content added
Line 132:
 
==== Exception declarations ====
<source lang=objc>
 
NSException *exception = [NSException exceptionWithName:@"myException"
reason:@"whatever" userInfo:nil];
</source>
 
==== Raising exceptions ====
<source lang=objc>
 
'''@throw''' exception;
</source>
 
==== Exception handling and propagation ====
<source lang=objc>
'''@try''' {
...
}
@catch (SomeException *se) {
// Handle a specific exception type.
...
}
'''@catch''' (NSException *ne) {
// Handle general exceptions.
...
 
// Propagate the exception so that it's handled at a higher level.
'''@try''' {
...@throw;
}
'''@catch''' (SomeExceptionid *seue) {
// Handle aCatch specificall exceptionthrown typeobjects.
...
}
'''@finally''' {
'''@catch''' (NSException *ne) {
// Perform cleanup, whether an exception occurred or not.
// Handle general exceptions.
...
}
</source>
// Propagate the exception so that it's handled at a higher level.
@throw;
}
'''@catch''' (id ue) {
// Catch all thrown objects.
...
}
'''@finally''' {
// Perform cleanup, whether an exception occurred or not.
...
}
 
===[[Ruby programming language|Ruby]]===