Exceptions: Difference between revisions

added objective-c
(omit m4)
(added objective-c)
Line 701:
====Shorthand====
<lang moo>`this:foo()!ANY=>this:bar()';</lang>
 
=={{header|Objective-C}}==
 
===Defining exceptions===
Exceptions can be any Objective-C object, though they are usually instances of <code>NSException</code>. You can create a subclass of NSException if necessary:
<lang objc>@interface MyException : NSException {
//Put specific info in here
}
@end</lang>
 
===Throw exceptions===
<lang objc>- (void)foo {
@throw [NSException exceptionWithName:@"TerribleException"
reason:@"OMGWTFBBQ111!1" userInfo:nil];
}</lang>
 
===Catching exceptions===
<lang objc>@try {
[self foo];
}
@catch (MyException *exc) {
//Catch only your specified type of exception
}
@catch (NSException *exc) {
//Catch any NSException or subclass
}
@catch (id exc) {
//Catch any kind of object
}
@finally {
//This code is always executed after exiting the try block
}</lang>
 
=={{header|OCaml}}==
Anonymous user