Exception handling syntax: Difference between revisions

Content deleted Content added
[[Perl]]: Perl uses die to throw
Added Objective-C
Line 117:
} finally {
// This optional section is executed upon termination of any of the try or catch blocks above
}
 
=== [[Objective-C]] ===
 
==== Exception declarations ====
 
NSException *exception = [NSException exceptionWithName:@"myException"
reason:@"whatever" userInfo:nil];
 
==== Raising exceptions ====
 
'''@throw''' exception;
 
==== Exception handling and propagation ====
 
'''@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.
@throw;
}
'''@catch''' (id ue) {
// Catch all thrown objects.
...
}
'''@finally''' {
// Perform cleanup, whether an exception occurred or not.
...
}