有没有办法捕获或处理EXC_BAD_ACCESS? [英] Is there a way to catch or handle EXC_BAD_ACCESS?
问题描述
据我了解,EXC_BAD_ACCESS会在您尝试访问不良内存时发生(如果我错了,请随时纠正我)?
As far as I understand, EXC_BAD_ACCESS happens when you try to access bad memory (feel free to correct me if I'm wrong)?
有没有办法有点像 try-catch
在 Java
中捕获它以防止应用程序完全失败?
Is there a way to kind of catch it like in a try-catch
in Java
to prevent total app failure?
推荐答案
不; EXC_BAD_ACCESS
意味着事情已经过时了。您的程序正在尝试访问无效的内存地址。即内存已损坏且没有可预测的恢复。
Nope; EXC_BAD_ACCESS
means things have gone wildly off the rails. Your program is trying to access a memory address that is invalid. I.e. memory has been corrupted and there is no predictable recovery.
这可能是内存管理问题。如果您可以重现该问题,请启用NSZombies并查看会发生什么。或者在这里发布回溯。
It may be a memory management issue. If you can reproduce the issue, turn on NSZombies and see what happens. Or post the backtrace here.
请注意,try-catch样式异常在iOS / Cocoa中也是不可恢复的。异常不能用于可恢复的错误处理。这就是NSError的用途。
Note that try-catch style exceptions are non-recoverable in iOS/Cocoa, too. Exceptions are not to be used for recoverable error handling. That is what NSError is for.
这篇关于有没有办法捕获或处理EXC_BAD_ACCESS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!