ios - 如何使用 NSSetUncaughtExceptionHandler 获取未捕获异常的类、方法和行号
<p><p>我使用 <code>NSSetUncaughtExceptionHandler(&HandleExceptions);</code> 来处理方法中未捕获的异常</p>
<pre><code>void HandleExceptions(NSException *exception)
{
}
</code></pre>
<p>我想打印发生异常的类、方法和行号有什么解决办法吗??</p>
<p>我正在跟踪堆栈跟踪</p>
<pre><code>0 appName 0x00000001000b6a20 HandleExceptions + 584
1 appName 0x00000001002175f0 GAIUncaughtExceptionHandler + 716
2 CoreFoundation 0x00000001852fe95c <redacted> + 692
3 libobjc.A.dylib 0x0000000195a103b4 <redacted> + 116
4 libc++abi.dylib 0x0000000195211bb4 <redacted> + 16
5 libc++abi.dylib 0x000000019521173c __cxa_rethrow + 144
6 libobjc.A.dylib 0x0000000195a10294 objc_exception_rethrow + 44
7 CoreFoundation 0x00000001851e1154 CFRunLoopRunSpecific + 572
8 GraphicsServices 0x000000018e38b5a4 GSEventRunModal + 168
9 UIKit 0x0000000189b163c0 UIApplicationMain + 1488
10appName 0x00000001000a8584 main + 108
11libdyld.dylib 0x000000019607ea08 <redacted> + 4
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>处理程序获取 <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSException_Class/index.html#//apple_ref/occ/instp/NSException/callStackSymbols" rel="noreferrer noopener nofollow"><code>NSException</code></a> 的实例.有两种方法:<code>-callStackSymbols</code>和<code>-callStackReturnAddresses</code>。</p>
<p><code>-callStackSymbols</code>如果可能的话,给你回溯字符串。</p>
<p>看起来像这样:</p>
<pre><code>0 TestArrayCopy 0x0000000100000dfe - + 46
1 TestArrayCopy 0x0000000100000e97 main + 87
2 libdyld.dylib 0x00007fff940be5fd start + 1
3 ??? 0x0000000000000001 0x0 + 1
</code></pre>
<p>如你所见,有一个关于方法所有者的信息(<code>-</code> 用于实例方法)、类名(<code>MyClass</code>)和方法名(<code>方法</code>)。</p></p>
<p style="font-size: 20px;">关于ios - 如何使用 NSSetUncaughtExceptionHandler 获取未捕获异常的类、方法和行号,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27960178/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27960178/
</a>
</p>
页:
[1]