NSSetUncaughtExceptionHandler not catches the exception in swift But Crittercism does it

1.1k Views Asked by At

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

There are 1 best solutions below

1
On

Initialize Crittercism before installing the NSSetUncaughtExceptionHandler.

And at the beginning of your handler, call:

[Crittercism logHandledException:exception]; // ObjC

or Crittercism.logHandledException(exception) // Swift