Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS + How to catch unhandled exception

We are writing static library. We have done exception handling for the exposed APIs. But still there are few un-handled Exceptions (or OS Exceptions). Can you please let me know how to catch these unhandled Exceptions. Thanks

like image 798
macdev30 Avatar asked Aug 16 '11 04:08

macdev30


3 Answers

Well, you could always rely on the Catch'em All Principle

For this kind of problem, I always use following code:

@try {
    // do something
}
@catch (NSException *exception) {
    // error happened! do something about the error state
}
@finally {
    // do something to keep the program still running properly
}
like image 58
Faizan S. Avatar answered Nov 09 '22 02:11

Faizan S.


You can use NSSetUncaughtExceptionHandler, you probably should add it to AppDelegate

you can finde example on this page: http://www.learn-cocos2d.com/tag/nssetuncaughtexceptionhandler/

like image 45
Maciek Sawicki Avatar answered Nov 09 '22 02:11

Maciek Sawicki


Simple -

       @try
        {
             //your code
        }
        @catch (NSException *theException) 
        {
            NSLog(@"Exception: %@", theException);
        }

Happy coding ...

like image 3
Srikar Appalaraju Avatar answered Nov 09 '22 03:11

Srikar Appalaraju