Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / Foundation / NSException / NSException.h
blobb7d0d640abcefefe060d85f9a470cc8b546170c5
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
9 #import <Foundation/NSObject.h>
10 #include <setjmp.h>
12 @class NSDictionary, NSArray;
14 FOUNDATION_EXPORT NSString *const NSGenericException;
15 FOUNDATION_EXPORT NSString *const NSInvalidArgumentException;
16 FOUNDATION_EXPORT NSString *const NSRangeException;
18 FOUNDATION_EXPORT NSString *const NSInternalInconsistencyException;
19 FOUNDATION_EXPORT NSString *const NSMallocException;
21 FOUNDATION_EXPORT NSString *const NSParseErrorException;
22 FOUNDATION_EXPORT NSString *const NSInconsistentArchiveException;
24 @interface NSException : NSObject <NSCoding, NSCopying> {
25 NSString *_name;
26 NSString *_reason;
27 NSDictionary *_userInfo;
28 NSArray *_callStack;
31 + (void)raise:(NSString *)name format:(NSString *)format, ...;
32 + (void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)arguments;
34 - initWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
36 + (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
38 - (void)raise;
40 - (NSString *)name;
41 - (NSString *)reason;
42 - (NSDictionary *)userInfo;
44 - (NSArray *)callStackReturnAddresses;
46 @end
48 typedef void NSUncaughtExceptionHandler(NSException *exception);
50 FOUNDATION_EXPORT NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void);
51 FOUNDATION_EXPORT void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *);
53 typedef struct NSExceptionFrame {
54 jmp_buf state;
55 struct NSExceptionFrame *parent;
56 NSException *exception;
57 } NSExceptionFrame;
59 FOUNDATION_EXPORT void __NSPushExceptionFrame(NSExceptionFrame *frame);
60 FOUNDATION_EXPORT void __NSPopExceptionFrame(NSExceptionFrame *frame);
62 #define NS_DURING \
63 { \
64 NSExceptionFrame __exceptionFrame; \
65 __NSPushExceptionFrame(&__exceptionFrame); \
66 if(setjmp(__exceptionFrame.state) == 0) {
68 #define NS_HANDLER \
69 __NSPopExceptionFrame(&__exceptionFrame); \
70 } \
71 else { \
72 NSException *localException = __exceptionFrame.exception; \
73 if(localException) { /* caller does not have to read localException */ \
76 #define NS_ENDHANDLER \
77 } \
80 #define NS_VALUERETURN(val, type) \
81 { \
82 __NSPopExceptionFrame(&__exceptionFrame); \
83 return val; \
86 #define NS_VOIDRETURN \
87 { \
88 __NSPopExceptionFrame(&__exceptionFrame); \
89 return; \
92 #import <Foundation/NSAssertionHandler.h>