Created
February 9, 2013 20:45
-
-
Save yetanotherchris/4747042 to your computer and use it in GitHub Desktop.
C# to Objective C by example #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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