iOS + How to catch unhandled exception

后端 未结 3 1009
生来不讨喜
生来不讨喜 2021-02-19 06:37

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

相关标签:
3条回答
  • 2021-02-19 07:08

    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/

    0 讨论(0)
  • 2021-02-19 07:13

    Simple -

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

    Happy coding ...

    0 讨论(0)
  • 2021-02-19 07:21

    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
    }
    
    0 讨论(0)
提交回复
热议问题