LoginSignup
15
15

More than 5 years have passed since last update.

クラッシュイベントを受け取り Stack Trace を出力する

Posted at

クラッシュイベントを受け取って何かしたい場合は、 NSSetUncaughtExceptionHandler() にハンドラ関数のポインタを渡すだけ。

NSSetUncaughtExceptionHandler(&exceptionHandler);

例外発生時に実行するハンドラ関数は、こんな感じで実装します。
(下記サンプルでは、スタックトレース結果をログ出力しています)

void exceptionHandler(NSException *exception)
{
    NSString *trace = [[exception callStackReturnAddresses] componentsJoinedByString:@"\n"];
    NSLog(@"Stack: (\n%@\n)", trace);
}
15
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15