ExceptionUtils.h
author Jens Alfke <jens@mooseyard.com>
Sat May 31 11:26:17 2008 -0700 (2008-05-31)
changeset 12 66b870428f85
parent 10 82a37ccf6b8c
permissions -rw-r--r--
* Worked around compiler warnings in Test.h when building for iPhone.
* Made Mercurial ignore the documentation files.
     1 //
     2 //  ExceptionUtils.h
     3 //  MYUtilities
     4 //
     5 //  Created by Jens Alfke on 1/5/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //  See BSD license at bottom of ExceptionUtils.m.
     8 //
     9 
    10 #import <Foundation/Foundation.h>
    11 
    12 
    13 #ifdef NSAppKitVersionNumber10_4 // only enable this in a project that uses AppKit
    14 /** Edit your Info.plist to make this your app's principal class,
    15     and most exceptions will be reported via a modal alert. 
    16     This includes exceptions caught by AppKit (i.e. uncaught ones from event handlers)
    17     and ones you report yourself via MYReportException and @catchAndReport. */
    18 @interface MYExceptionReportingApplication : NSApplication
    19 @end
    20 #endif
    21 
    22 
    23 /** A useful macro to use in code where you absolutely cannot allow an exception to 
    24     go uncaught because it would crash (e.g. in a C callback or at the top level of a thread.)
    25     It catches the exception but makes sure it gets reported. */
    26 #define catchAndReport(MSG...) @catch(NSException *x) {MYReportException(x,MSG);}
    27 
    28 
    29 /** Report an exception that's being caught and consumed.
    30     Logs a warning to the console, and calls the current MYReportException target if any. */
    31 void MYReportException( NSException *x, NSString *where, ... );
    32 
    33 
    34 /** Sets a callback to be invoked when MYReportException is called.
    35     In a GUI app, the callback would typically call [NSApp reportException: theException].
    36     The ExceptionReportingApplication class, below, sets this up automatically. */
    37 void MYSetExceptionReporter( void (*reporter)(NSException*) );
    38 
    39 
    40 @interface NSException (MYUtilities)
    41 /** Returns a textual, human-readable backtrace of the point where the exception was thrown. */
    42 - (NSString*) my_callStack;
    43 @end
    44 
    45 
    46 BOOL IsGDBAttached( void );