Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# to Objective C by example #4
-(void) exceptionExample
{
//
// Catching exceptions should be familiar to C# programmers
//
@try
{
}
@catch (NSException *exception)
{
NSLog(@"%@ error occured - %@",[exception name], [exception reason]);
}
@finally
{
// Some clean up code
}
//
// Throwing an exception. Apple says:
// "Instead of exceptions, error objects (NSError) and the Cocoa error-delivery mechanism are the
// recommended way to communicate expected errors in Cocoa applications"
//
NSException* myException = [NSException exceptionWithName:@"FileNotFoundException"
reason:@"File Not Found on System"userInfo:nil];
@throw myException;
// Or..
[NSException raise:@"My reason" format:@"format string here", myobject]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.