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