Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created February 9, 2013 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4747042 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4747042 to your computer and use it in GitHub Desktop.
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