0

I want to be able to set a global function in my app delegate so I can log all uncaught exceptions.

Is there a way I can catch all uncaught exceptions, so I can log them to a file? I already have the file being created so I just need and way to call a method for unhandled exceptions.

Nick Turner
  • 927
  • 1
  • 11
  • 21
  • 1
    See the technique used [here](http://stackoverflow.com/a/12268397/581994). Just substitute your log mechanism for NSLog. (But note that this will catch only NSExceptions, not C++ exceptions or "signals".) – Hot Licks Jan 16 '13 at 16:27

1 Answers1

5

While there are some quick solutions to this (NSUncaughtExceptionHandler and the like), handling all the cases that you likely want to handle is quite complex. For instance, I assume you really want to catch crashes due to signals (SEGV), not just crashes due to ObjC exceptions.

IMO, this is not something you want to build from scratch. Use a framework designed for it. My favorite frameworks for solving this are PLCrashReporter and QuincyKit (which uses PLCrashReporter).

Rob Napier
  • 286,113
  • 34
  • 456
  • 610