Source

MYUtilities / ExceptionUtils.h

//
//  ExceptionUtils.h
//  MYUtilities
//
//  Created by Jens Alfke on 1/5/08.
//  Copyright 2008 Jens Alfke. All rights reserved.
//  See BSD license at bottom of ExceptionUtils.m.
//

#import <Foundation/Foundation.h>


#ifdef NSAppKitVersionNumber10_4 // only enable this in a project that uses AppKit
/** Edit your Info.plist to make this your app's principal class,
    and most exceptions will be reported via a modal alert. 
    This includes exceptions caught by AppKit (i.e. uncaught ones from event handlers)
    and ones you report yourself via MYReportException and @catchAndReport. */
@interface MYExceptionReportingApplication : NSApplication
@end
#endif


/** A useful macro to use in code where you absolutely cannot allow an exception to 
    go uncaught because it would crash (e.g. in a C callback or at the top level of a thread.)
    It catches the exception but makes sure it gets reported. */
#define catchAndReport(MSG...) @catch(NSException *x) {MYReportException(x,MSG);}


/** Report an exception that's being caught and consumed.
    Logs a warning to the console, and calls the current MYReportException target if any. */
void MYReportException( NSException *x, NSString *where, ... );


/** Sets a callback to be invoked when MYReportException is called.
    In a GUI app, the callback would typically call [NSApp reportException: theException].
    The ExceptionReportingApplication class, below, sets this up automatically. */
void MYSetExceptionReporter( void (*reporter)(NSException*) );


@interface NSException (MYUtilities)
/** Returns a textual, human-readable backtrace of the point where the exception was thrown. */
- (NSString*) my_callStack;
@end


BOOL IsGDBAttached( void );
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.