gpt4 book ai didi

ios - 我是如何在@try/@catch block 中崩溃的?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:30 25 4
gpt4 key购买 nike

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

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) {...}

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

我没有从 catch 内部调用 throwing 方法。我所做的只是将异常、webView 和 htmlString 转储到 NSLog。如果它们导致了异常,我希望崩溃堆栈看起来会有所不同。

这似乎会减少为潜在的操作系统错误?

最佳答案

这是一个段错误 (SIGSEGV),不是异常。

这些错误并非异常(exception),这意味着您不能使用 try/catch block 。

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

在你的情况下,这可能是因为自动释放的对象被释放,然后被访问(指针不再有效,因为对象被释放)。

确保您的 htmlString 变量仍然指向一个有效的对象...

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

关于ios - 我是如何在@try/@catch block 中崩溃的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9825832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com