jens@10: // jens@10: // ExceptionUtils.h jens@10: // MYUtilities jens@10: // jens@10: // Created by Jens Alfke on 1/5/08. jens@10: // Copyright 2008 Jens Alfke. All rights reserved. jens@10: // See BSD license at bottom of ExceptionUtils.m. jens@10: // jens@10: jens@11: #import jens@10: jens@10: jens@11: #ifdef NSAppKitVersionNumber10_4 // only enable this in a project that uses AppKit jens@10: /** Edit your Info.plist to make this your app's principal class, jens@10: and most exceptions will be reported via a modal alert. jens@10: This includes exceptions caught by AppKit (i.e. uncaught ones from event handlers) jens@10: and ones you report yourself via MYReportException and @catchAndReport. */ jens@10: @interface MYExceptionReportingApplication : NSApplication jens@10: @end jens@11: #endif jens@10: jens@10: jens@10: /** A useful macro to use in code where you absolutely cannot allow an exception to jens@10: go uncaught because it would crash (e.g. in a C callback or at the top level of a thread.) jens@10: It catches the exception but makes sure it gets reported. */ jens@10: #define catchAndReport(MSG...) @catch(NSException *x) {MYReportException(x,MSG);} jens@10: jens@10: jens@10: /** Report an exception that's being caught and consumed. jens@10: Logs a warning to the console, and calls the current MYReportException target if any. */ jens@10: void MYReportException( NSException *x, NSString *where, ... ); jens@10: jens@10: jens@10: /** Sets a callback to be invoked when MYReportException is called. jens@10: In a GUI app, the callback would typically call [NSApp reportException: theException]. jens@10: The ExceptionReportingApplication class, below, sets this up automatically. */ jens@10: void MYSetExceptionReporter( void (*reporter)(NSException*) ); jens@10: jens@10: jens@10: @interface NSException (MYUtilities) jens@10: /** Returns a textual, human-readable backtrace of the point where the exception was thrown. */ jens@10: - (NSString*) my_callStack; jens@10: @end jens@11: jens@11: jens@11: BOOL IsGDBAttached( void );