NSSetUncaughtExceptionHandler不能迅速捕获异常,但Crittercism可以做到 [英] NSSetUncaughtExceptionHandler not catches the exception in swift But Crittercism does it

查看:254
本文介绍了NSSetUncaughtExceptionHandler不能迅速捕获异常,但Crittercism可以做到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSSetUncaughtExceptionHandler 是要捕获异常并将其转储到某个地方,以便我们可以找到应用程序崩溃的原因以及异常是什么.

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.

在目标C中,它按预期捕获异常.这是引用

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

但是在异常出现时迅速将其捕获.这是我在didFinishLaunchingWithOptions

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.

推荐答案

在安装NSSetUncaughtExceptionHandler之前初始化Crittercism.

Initialize Crittercism before installing the NSSetUncaughtExceptionHandler.

然后在处理程序的开头,调用:

And at the beginning of your handler, call:

[Crittercism logHandledException:exception];//ObjC

[Crittercism logHandledException:exception]; // ObjC

或 Crittercism.logHandledException(exception)//迅速

or Crittercism.logHandledException(exception) // Swift

这篇关于NSSetUncaughtExceptionHandler不能迅速捕获异常,但Crittercism可以做到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆