ExceptionUtils.h
author snej@snej-mbp.mtv.corp.google.com
Tue Apr 07 11:13:25 2009 -0700 (2009-04-07)
changeset 23 a910102a1c9d
parent 10 82a37ccf6b8c
permissions -rw-r--r--
* Added MYReturnError.
* Better iPhone support in ExceptionUtils.
* Make sure "All Tests Passed/Failed" message is always logged.
     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 );