我如何在@ try / @ catch块中崩溃? [英] How did I crash in a @try/@catch block?
问题描述
我收到以下崩溃报告(截断)
异常类型:EXC_CRASH(SIGSEGV)
异常代码: 0x00000000,0x00000000
崩溃线程:0
线程0名称:调度队列:com.apple.main线程
线程0崩溃:
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){...}
那么,我是如何设法从一个异常处理程序中抛出一个异常?
我没有从catch中调用throw方法。所有我在做的是转储到NSLog的异常,webView和htmlString。如果他们导致异常,我会期望崩溃堆栈看起来有所不同。
这是否似乎减少到潜在的操作系统错误?
这是一个细分错误(SIGSEGV),不是例外。 b
$ b
这些错误不是例外,这意味着你不能使用try / catch块。
分段错误意味着你是尝试访问不属于您的应用程序的内存区域。
在您的情况下,可能是自动释放的对象被释放,然后访问(指针不再有效,因为对象被释放)
确保你的 htmlString
变量仍然指向到一个有效的对象...
顺便说一句,我不认为在使用后需要调用 setNeedsDisplay
loadHTMLString
。
I received the following crash report (truncated)
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
The concern is that the calling code looks like this:
@try {
[webView loadHTMLString:htmlString baseURL:nil];
[webView setNeedsDisplay];
}
@catch (NSException *exception) {...}
So, how did I manage to throw an exception from within an exception handler?
I didn't call the throwing method from inside catch. All I'm doing there is dumping to NSLog the exception, the webView, and the htmlString. If they were causing the exception I would expect the crash stack to look differently.
Does this seem to reduce into a potential OS bug?
This is a segmentation fault (SIGSEGV), not an exception.
Those faults aren't exceptions, meaning you can't use a try/catch block.
A segmentation fault means you are trying to access a memory region that doesn't belong to your app.
In your case, it may be cause be auto-released objects that gets deallocated, and then accessed (the pointer is not valid anymore, since the object was deallocated).
Ensure your htmlString
variable is still pointing to a valid object...
By the way, I don't think calling setNeedsDisplay
is needed after using loadHTMLString
.
这篇关于我如何在@ try / @ catch块中崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!