NSSetUncaughtExceptionHandler not catches the exception in swift But Crittercism does it

不羁岁月 提交于 2019-12-10 10:02:05

问题


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:


Initialize Crittercism before installing the NSSetUncaughtExceptionHandler.

And at the beginning of your handler, call:

[Crittercism logHandledException:exception]; // ObjC

or Crittercism.logHandledException(exception) // Swift



来源:https://stackoverflow.com/questions/35557716/nssetuncaughtexceptionhandler-not-catches-the-exception-in-swift-but-crittercism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!