如何捕获全局异常? [英] How do I catch global exceptions?

查看:229
本文介绍了如何捕获全局异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在代码中捕获全局崩溃应用程序异常(如objc_exception_throw,EXC_ARITHMETIC等)?

Is there a way to catch global "crashing" app exceptions like objc_exception_throw, EXC_ARITHMETIC etc. in code? I need that because I want to do some things before the app gets killed by the system.

推荐答案

您可以设置一个处理程序任何未捕获的异常使用 NSSetUncaughtExceptionHandler

You can set a handler for any uncaught exception by using NSSetUncaughtExceptionHandler.

Apple的相关文档在这里: http:// developer .apple.com / mac / library / documentation / cocoa / conceptual / Exceptions / Concepts / UncaughtExceptions.html#// apple_ref / doc / uid / 20000056-BAJDDGGD

The relevant docs from Apple are here: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/Exceptions/Concepts/UncaughtExceptions.html#//apple_ref/doc/uid/20000056-BAJDDGGD

这篇关于如何捕获全局异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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