macdev30
macdev30

Reputation: 245

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

Upvotes: 14

Views: 18471

Answers (3)

Maciek Sawicki
Maciek Sawicki

Reputation: 6835

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/

Upvotes: 10

Faizan S.
Faizan S.

Reputation: 8644

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
}

Upvotes: 11

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73608

Simple -

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

Happy coding ...

Upvotes: 3

Related Questions