3

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.

4

1 回答 1

0

在安装 NSSetUncaughtExceptionHandler 之前初始化 Crittercism。

在你的处理程序开始时,调用:

[Crittercism logHandledException:异常];// 对象

或 Crittercism.logHandledException(exception) // Swift

于 2016-07-08T00:15:50.123 回答