6

In Xcode I can create a breakpoint to catch all exceptions (exception breakpoint). However this breakpoint will also fire in a try-catch situation.

I'm using third party libraries, so the try-catch situation is a fact, not an option.

Is there a way to only handle the uncaught exceptions, instead of all exceptions?

justin
  • 104,054
  • 14
  • 179
  • 226
Yvo
  • 18,681
  • 11
  • 71
  • 90

1 Answers1

0

You can put a top-level try/catch at your threads' entries.

You may also be interested in NSSetUncaughtExceptionHandler.

Normally, top level handlers are of little utility in production (you're really not attempting to recover from a problem you aren't prepared to handle, but it may be useful for last words or breakpoints). Ideally, you would guard your exits from those library interfaces with a try/catch if and only if you could handle the the exception. Either that, or nothrow as a quick debugging utility during development.

If you're trying to catch Cocoa exceptions -- just let it die and file bugs to whoever thought Cocoa exceptions were supposed to be recoverable.

justin
  • 104,054
  • 14
  • 179
  • 226
  • 1
    Thanks. I dug up a bit of info on the NSSetUncaughtExceptionHandler: http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html, for other people reading this. – Yvo Oct 02 '12 at 05:55
  • 1
    "Normally, top level handlers are of little utility in production" From my experience they're super valuable for reporting errors in production. – Steven Wexler May 11 '15 at 18:26