如何使用NSSetUncaughtExceptionHandler获取未捕获的exception的类,方法和行号
我使用了NSSetUncaughtExceptionHandler(&HandleExceptions);
用于处理方法中未捕获的exception
void HandleExceptions(NSException *exception) { }
我想打印类,方法和行号,发生exception的任何解决scheme?
我得到以下堆栈跟踪
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 10 appName 0x00000001000a8584 main + 108 11 libdyld.dylib 0x000000019607ea08 <redacted> + 4
处理程序获取NSException
一个实例。 有两种方法: -callStackSymbols
和-callStackReturnAddresses
。
-callStackSymbols
给你回溯string,如果可能的话。
它看起来像这样:
0 TestArrayCopy 0x0000000100000dfe -[MyClass method] + 46 1 TestArrayCopy 0x0000000100000e97 main + 87 2 libdyld.dylib 0x00007fff940be5fd start + 1 3 ??? 0x0000000000000001 0x0 + 1
正如你所看到的,有关于方法所有者的信息(例如方法),类名( MyClass
)和方法名( method
)。
- NSInteralInconsistencyException – UIKeyboardLayoutAlignmentView
- initWithString的NSURL对象给出了 – 错误
- iOS中的例外Handeling
- CRASH:*** – :index bound 4294967295 beyond bounds
- 在Swift 2中捕捉“IndexOutOfBoundsException”
- EXC_BAD_ACCESS自动处理
- 'NSInvalidArgumentException':尝试滚动到无效的索引path
- 如何捕捉Swift崩溃并做一些日志logging
- NSCFType的iOSexception是什么?