tags:

views:

211

answers:

2

Windows has SetUnhandledExceptionFilter API to enable applications to handle crashes. Is there something similar for the Mac platform? I didn't find anything like it on developer.apple.com...

Thanks!

+2  A: 

Take a look at Smart Crash Reports and how it works. Be warned that it's a truly evil hack.

Jim Puls
Thanks, but I'm not really looking for my crashes to be routed to me via 3rd party. I just need to provide my own EH where I can do things that interest me, so something very similar to SetUnhandledExceptionFilter for Windows.
psychotik
+1  A: 

The Cocoa/Foundation equivalent is the NSSetUncaughtExceptionHandler() function. You should also check out the Controlling a Program's Response to an Exception section of the Exception Handling Guide for Cocoa. It will explain some defaults changes you can make to have your application do specific, predefined things when the NSApplication object wants to terminate with an exception.

Jason Coco
Hmmm... this looks very promising, except that it won't really work. Here's what I have: global function: void GlobalFilter (NSException *pException) { // do something}in post-app-init code: NSSetUncaughtExceptionHandler(To test, I wrote a method that does this: wstring foo = NULL; foo->size();My program crashes but my handler is never invoked... Any ideas why this might not work, or what I'm doing wrong?
psychotik
Yes, your program isn't generating an exception, it's generating a bus error. The standard signal handler for that will basically create a file in your CrashReporter directory. In order to do something else, you would have to install a new signal handler for SIGSEGV and SIGBUS. See the man page for signal(2) for more information on that. The NSSetUncaughtExceptionHandler() helps when an uncaught Objective-C exception is terminating your application.
Jason Coco
Got it... thanks! I guess I really should add both types of handlers then. Thanks!
psychotik