iphone - @try @catch 是否适用于 SIGSEGV/SEGV_ACCERR

标签 iphone objective-c ios segmentation-fault

我在 third party component 中发生了崩溃。很明显,这是有一个我必须研究的根本原因。但为了同时使其更加稳健,我想用 @try @catch block 包围崩溃的调用。

到目前为止,我无法重现崩溃,因此我无法真正判断 @try @catch 在这种情况下是否有效。我的问题是 @try@catch 通常在什么类型的情况下起作用。

Hardware Model:      iPhone3,1
Process:         MyApp [2084]
Path:            /var/mobile/Applications/8B400A7D-88E7-4319-9C5D-F7E72DE8D960/MyApp.app/MyApp
Identifier:      com.company.MyApp-Snapshot
Version:         7.2
Code Type:       ARM
Parent Process:  launchd [1]

Date/Time:       2012-09-07 14:04:14 +0000
OS Version:      iPhone OS 5.1.1 (9B206)
Report Version:  104

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0xe1088602
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib    0x35260f78 objc_msgSend + 15
1   UIKit              0x312363d7 -[UIView(Hierarchy) superview] + 50
***************************************************************************                     |<---- UIView *superview = self.superview;
2   MyApp              0x000238f9 -[MBProgressHUD deviceOrientationDidChange:] (MBProgressHUD.m:622)
***************************************************************************
3   Foundation         0x37dc64ff __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 18
4   CoreFoundation     0x3752d547 ___CFXNotificationPost_block_invoke_0 + 70
5   CoreFoundation     0x374b9097 _CFXNotificationPost + 1406
6   Foundation         0x37d3a3eb -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
7   UIKit              0x3123adeb -[UIDevice setOrientation:animated:] + 214
8   UIKit              0x3123616f -[UIApplication handleEvent:withNewEvent:] + 2718
9   UIKit              0x31235567 -[UIApplication sendEvent:] + 54
10  UIKit              0x31234f3b _UIApplicationHandleEvent + 5826
11  GraphicsServices   0x33c7722b PurpleEventCallback + 882
12  CoreFoundation     0x37535523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
13  CoreFoundation     0x375354c5 __CFRunLoopDoSource1 + 140
14  CoreFoundation     0x37534313 __CFRunLoopRun + 1370
15  CoreFoundation     0x374b74a5 CFRunLoopRunSpecific + 300
16  CoreFoundation     0x374b736d CFRunLoopRunInMode + 104
17  GraphicsServices   0x33c76439 GSEventRunModal + 136
18  UIKit              0x31263cd5 UIApplicationMain + 1080
19  MyApp              0x00003643 main (main.m:16)

更新:Apparently SIGSEGV 不是一个可以捕获的异常,而是由访问无效内存引起的。从我的角度来看,能够捕获此类异常仍然很方便,尽管找到问题的根源显然是解决问题的更好方法。

最佳答案

不幸的是,当代码抛出异常时,try-catch 框架会很好,但对“信号”没有帮助。 (“SIGSEGV”中的“SIG”表示这是一个信号。)

为了处理信号,您必须为应用程序指定一个信号处理程序,当信号触发时系统将调用该处理程序。

对于任何类型的 SIGSEGV(堆栈以 objc_msgSend 结尾),您很可能有代码尝试调用已释放对象的方法。

在设备上,您可以在启用“NSZombies”的情况下运行以提供帮助。这将保留少量对象,以便在您尝试向它们发送消息时抛出异常。

当堆栈以 objc_msgSend 结尾时,堆栈可能会被奇怪地修改,因此实际问题点可能与您在崩溃日志堆栈中看到的不同。

关于iphone - @try @catch 是否适用于 SIGSEGV/SEGV_ACCERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12384127/

相关文章:

objective-c - 删除 View 、ARC、与 Objective C 和 Swift 的差异

iphone - Objective-C : Is there a difference between these two statements?

ios - iPhone错误-未从App Store安装此应用,必须手动安装

ios - 如何以美国格式 (DD/MM/YY) 显示日期选择器?

iPhone SDK 4.3 libav编译问题

iphone - 您需要 Xcode 来编写 iPhone 应用程序吗?

ios - 将 iPhone 应用程序分发给测试人员?

objective-c - 什么在子类化 UIViewController 时调用 viewDidLoad?

ios - 从 mapView 中删除一条折线

iphone - GData YouTube视频上传的音频丢失