The try{}catch
construct is common to C++, Java & related languages. In the iOS SDK is there and any functionality like this?
-
possible duplicate of Try-catch exception handling practice for iPhone/Objective-C– ceejayozApr 18, 2011 at 14:06
-
6Some advice since it looks like you're coming over from the Java world: in iOS exceptions are rarely used for program control. An exception almost always means that the programmer did something wrong and it should be fixed. developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/…– kubiApr 18, 2011 at 14:13
-
2Here's a better link that describes the role of exceptions in Cocoa/iOS: developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/…– kubiApr 18, 2011 at 14:20
Add a comment
|
1 Answer
@try {
// Try something
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
@finally {
// Added to show finally works as well
}
-
4Curious: is there EVER a situation where the exception caught would not be of type
NSException
? More importantly, is there ever a situation in which theNSLog
could blow up? If you think this is a different question, let me know and I'll ask it properly. Jan 12, 2012 at 19:12 -
Yes, you can capture a specific exception or a custom exception. Check out the example under "Catching Different Types of Exception". developer.apple.com/library/ios/#documentation/cocoa/conceptual/… Nov 29, 2012 at 4:41