更新:
当尝试取消引用无效指针时,代码崩溃.这是一个第三方库,它与外部硬件接口,所以我无法在本地调试.我试图阻止它崩溃并输出数据到我的应用程序调试控制台.
解决方法
The standard Cocoa convention is that exceptions signal programmer error and are not intended to be recovered from. Making code exceptions-safe by default would impose severe runtime and code size penalties on code that typically does not actually care about exceptions safety. Therefore,ARC-generated code leaks by default on exceptions,which is just fine if the process is going to be immediately terminated anyway. Programs which do care about recovering from exceptions should enable the option [-fobjc-arc-exceptions,which imposes speed and memory penalties on your program].
EXC_BAD_ACCESS也是如此.您可以用信号处理程序来捕获它,目的是记录一些信息,然后完成您的崩溃.要做一个很好的工具,请参阅PLCrashReporter.正确编写这样的处理程序是非常困难的,所以我强烈建议使用现有的框架.如果您错误地抓到EXC_BAD_ACCESS,您可以很容易地陷入用户电池的死锁.