NSSetUncaughtExceptionHandler not catches the exce

2019-05-14 01:33发布

Purpose of NSSetUncaughtExceptionHandler is to catch the exception and dump it somewhere so that we can find why the app crashed and what is the exception.

In Objective C it catches the exception as expected..Here is the reference

But in swift when an exception arises its not caught. Here is the code that I used in didFinishLaunchingWithOptions

 NSSetUncaughtExceptionHandler { exception in
            NSUserDefaults.standardUserDefaults().setObject("Exception Details Are \n\nExceptionName--> \(exception.name) \nReason -->\(exception.reason!)\n\(exception.description)", forKey: "Exception")
            NSUserDefaults.standardUserDefaults().setObject("Call Stack Symbols:\(exception.callStackSymbols)", forKey: "ExceptionCallstack")
            NSUserDefaults.standardUserDefaults().synchronize()
        }

Here is the snippet that I use to crash the app

    var c=["a","b","c"]
    var d=c[4]

Can anybody tell me what I am doing wrong here.

1条回答
时光不老,我们不散
2楼-- · 2019-05-14 02:33

Initialize Crittercism before installing the NSSetUncaughtExceptionHandler.

And at the beginning of your handler, call:

[Crittercism logHandledException:exception]; // ObjC

or Crittercism.logHandledException(exception) // Swift

查看更多
登录 后发表回答