-->

How to replace NSUncaughtExceptionHandler with def

2020-02-29 20:02发布

问题:

So far I used NSUncaughtExceptionHandler within code:

void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"*************************************************");
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
    NSLog(@"*************************************************");
}

NSUncaughtExceptionHandler *exceptionHandlerPtr = &uncaughtExceptionHandler;

I know that in Xcode I can Add Exception Breakpoint for all exceptions:

Then I can Edit Breakpoint:

and finally I do not know how to configure this to replace my code from NSUncaughtExceptionHandler.

回答1:

The simplest solution from WWDC 15 - Advanced Debugging and the Address Sanitizer.

Example output is:

You can also read Xcode: One Weird Debugging Trick That Will Save Your Life