Handling Global iOS Uncaught Exception

xCode debug 的時候常常會丟出一些不是人看的 exception 資訊,往往找到問題點時已花費不少時間,這裡提供兩個小技巧解決這個問題。

NSSetUncaughtExceptionHandler

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    // ...
}

在 xCode 裡可以直接加入 exception breakpoint 更方便。
command + 7 -> Add Exception Breakpoint