我是如何在@ try / @ catch块崩溃的?

我收到了以下崩溃报告(截断)

Exception Type: EXC_CRASH (SIGSEGV) Exception Codes: 0x00000000, 0x00000000 Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libsystem_kernel.dylib 0x36df00d8 __psynch_mutexwait + 24 1 libsystem_c.dylib 0x31760674 pthread_mutex_lock + 376 2 CoreFoundation 0x31f2338a CFRunLoopWakeUp + 50 3 WebCore 0x308d0bc8 _WebThreadRun + 284 4 UIKit 0x37921c7a -[UIWebDocumentView _runLoadBlock:] + 38 5 UIKit 0x37921c3a -[UIWebDocumentView _cleanUpFrameStateAndLoad:] + 114 6 UIKit 0x37921bbe -[UIWebDocumentView loadHTMLString:baseURL:] + 78 

关注的是调用代码如下所示:

 @try { [webView loadHTMLString:htmlString baseURL:nil]; [webView setNeedsDisplay]; } @catch (NSException *exception) {...} 

那么,我是如何设法从exception处理程序中抛出exception的呢?

我没有从catch内部调用throw方法。 我正在做的就是向NSLog转储exception,webView和htmlString。 如果它们导致exception,我希望崩溃堆栈看起来不同。

这似乎会降低为潜在的操作系统错误吗?

这是一个分段错误(SIGSEGV) ,不是例外。

这些错误不是例外,这意味着您不能使用try / catch块。

分段错误意味着您正在尝试访问不属于您的应用的内存区域。

在您的情况下,可能是因为自动释放的对象被取消分配,然后被访问(指针不再有效,因为该对象已被释放)。

确保您的htmlString变量仍指向有效对象…

顺便说一句,我不认为在使用loadHTMLString之后需要调用setNeedsDisplay