home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / Foundation.framework / Versions / B / Headers / NSException.h < prev    next >
Encoding:
Text File  |  1996-11-20  |  6.5 KB  |  210 lines

  1. /*    NSException.h
  2.     Exception raising and handling
  3.     Copyright 1994-1996, NeXT Software, Inc.  All rights reserved.
  4. */
  5.  
  6. #import <Foundation/NSObject.h>
  7. #import <stdarg.h>
  8. #import <setjmp.h>
  9.  
  10. @class NSString, NSDictionary;
  11.  
  12. /***************    Generic Exception names        ***************/
  13.  
  14. FOUNDATION_EXPORT NSString *NSGenericException;
  15. FOUNDATION_EXPORT NSString *NSRangeException;
  16. FOUNDATION_EXPORT NSString *NSInvalidArgumentException;
  17. FOUNDATION_EXPORT NSString *NSInternalInconsistencyException;
  18.  
  19. FOUNDATION_EXPORT NSString *NSMallocException;
  20.  
  21. #if !defined(STRICT_OPENSTEP)
  22.  
  23. FOUNDATION_EXPORT NSString *NSObjectInaccessibleException;
  24. FOUNDATION_EXPORT NSString *NSObjectNotAvailableException;
  25. FOUNDATION_EXPORT NSString *NSDestinationInvalidException;
  26.     
  27. FOUNDATION_EXPORT NSString *NSPortTimeoutException;
  28. FOUNDATION_EXPORT NSString *NSInvalidSendPortException;
  29. FOUNDATION_EXPORT NSString *NSInvalidReceivePortException;
  30. FOUNDATION_EXPORT NSString *NSPortSendException;
  31. FOUNDATION_EXPORT NSString *NSPortReceiveException;
  32.  
  33. FOUNDATION_EXPORT NSString *NSOldStyleException;
  34.  
  35. #endif /* !STRICT_OPENSTEP */
  36.  
  37. /***************    Exception object    ***************/
  38.  
  39. @interface NSException:NSObject <NSCopying, NSCoding> {
  40.     @private
  41.     NSString        *name;
  42.     NSString        *reason;
  43.     NSDictionary    *userInfo;
  44.     void        *reserved;
  45. }
  46.  
  47. + (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
  48.  
  49. - (NSString *)name;
  50.  
  51. - (NSString *)reason;
  52.  
  53. - (NSDictionary *)userInfo;
  54.  
  55. - (volatile void)raise;
  56.  
  57. - (id)initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo;
  58.  
  59. @end
  60.  
  61. @interface NSException (NSExceptionRaisingConveniences)
  62.  
  63. + (volatile void)raise:(NSString *)name format:(NSString *)format, ...;
  64.  
  65. + (volatile void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)argList;
  66.  
  67. @end
  68.  
  69. typedef struct _NSHandler {    /* Private */
  70.     jmp_buf        _state;
  71.     struct _NSHandler    *_next;
  72.     int         _code;
  73.     const void        *_data1;
  74.     const void        *_data2;
  75. } NSHandler;
  76.  
  77. /* private support routines.  Do not call directly. */
  78. FOUNDATION_EXPORT void _NSAddHandler(NSHandler *handler);
  79. FOUNDATION_EXPORT void _NSRemoveHandler(NSHandler *handler);
  80. FOUNDATION_EXPORT NSException *_NSExceptionObjectFromHandler(NSHandler *handler);
  81.  
  82. #if !defined(NSSETJMP)
  83. #if defined(__svr4__) || defined(WIN32)
  84. #define NSSETJMP(B, S)    setjmp(B)
  85. #elif defined(hpux)
  86. #define NSSETJMP(B, S)    sigsetjmp((B), (S))
  87. #else
  88. #define NSSETJMP(B, S)    _setjmp(B)
  89. #endif
  90. #endif
  91.  
  92. #define NS_DURING { NSHandler _localHandler;            \
  93.             _NSAddHandler(&_localHandler);        \
  94.             if (!NSSETJMP(_localHandler._state, 0)) {
  95.  
  96. #define NS_HANDLER _NSRemoveHandler(&_localHandler); } else { \
  97.             NSException    *localException = _NSExceptionObjectFromHandler(&_localHandler);
  98.  
  99. #define NS_ENDHANDLER localException = nil; /* to avoid compiler warning */}}
  100.  
  101. #define NS_VALUERETURN(val,type)  do { type temp = (val);    \
  102.             _NSRemoveHandler(&_localHandler);    \
  103.             return(temp); } while (0)
  104.  
  105. #define NS_VOIDRETURN    do { _NSRemoveHandler(&_localHandler);    \
  106.             return; } while (0)
  107.  
  108.  
  109. typedef volatile void NSUncaughtExceptionHandler(NSException *exception);
  110.  
  111. FOUNDATION_EXPORT NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void);
  112. FOUNDATION_EXPORT void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *);
  113.  
  114.  
  115. @class NSAssertionHandler;
  116.  
  117. /* Implementation of asserts (ignore) */
  118. #if !defined(NS_BLOCK_ASSERTIONS)
  119. #if !defined(_NSAssertBody)
  120. #define _NSAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5)    \
  121.     do {                        \
  122.     if (!(condition)) {                \
  123.         [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithCString:__FILE__] \
  124.             lineNumber:__LINE__ description:(desc), (arg1), (arg2), (arg3), (arg4), (arg5)];    \
  125.     }                        \
  126.     } while(0)
  127. #endif
  128. #if !defined(_NSCAssertBody)
  129. #define _NSCAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5)    \
  130.     do {                        \
  131.     if (!(condition)) {                \
  132.         [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__] file:[NSString stringWithCString:__FILE__] \
  133.             lineNumber:__LINE__ description:(desc), (arg1), (arg2), (arg3), (arg4), (arg5)];    \
  134.     }                        \
  135.     } while(0)
  136. #endif
  137. #else
  138. #if !defined(_NSAssertBody)
  139. #define _NSAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5)
  140. #endif
  141. #if !defined(_NSCAssertBody)
  142. #define _NSCAssertBody(condition, desc, arg1, arg2, arg3, arg4, arg5)
  143. #endif
  144. #endif
  145.  
  146.  
  147. /*
  148.  * Asserts to use in Objective-C method bodies
  149.  */
  150.  
  151. #define NSAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5)    \
  152.     _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
  153.  
  154. #define NSAssert4(condition, desc, arg1, arg2, arg3, arg4)    \
  155.     _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
  156.  
  157. #define NSAssert3(condition, desc, arg1, arg2, arg3)    \
  158.     _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
  159.  
  160. #define NSAssert2(condition, desc, arg1, arg2)        \
  161.     _NSAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
  162.  
  163. #define NSAssert1(condition, desc, arg1)        \
  164.     _NSAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
  165.  
  166. #define NSAssert(condition, desc)            \
  167.     _NSAssertBody((condition), (desc), 0, 0, 0, 0, 0)
  168.  
  169.  
  170. #define NSParameterAssert(condition)            \
  171.     _NSAssertBody((condition), @"Invalid parameter not satisfying: %s", #condition, 0, 0, 0, 0)
  172.  
  173. #define NSCAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5)    \
  174.     _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))
  175.  
  176. #define NSCAssert4(condition, desc, arg1, arg2, arg3, arg4)    \
  177.     _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), 0)
  178.  
  179. #define NSCAssert3(condition, desc, arg1, arg2, arg3)    \
  180.     _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), 0, 0)
  181.  
  182. #define NSCAssert2(condition, desc, arg1, arg2)    \
  183.     _NSCAssertBody((condition), (desc), (arg1), (arg2), 0, 0, 0)
  184.  
  185. #define NSCAssert1(condition, desc, arg1)        \
  186.     _NSCAssertBody((condition), (desc), (arg1), 0, 0, 0, 0)
  187.  
  188. #define NSCAssert(condition, desc)            \
  189.     _NSCAssertBody((condition), (desc), 0, 0, 0, 0, 0)
  190.  
  191.  
  192. #define NSCParameterAssert(condition)            \
  193.     _NSCAssertBody((condition), @"Invalid parameter not satisfying: %s", #condition, 0, 0, 0, 0)
  194.  
  195.  
  196. @interface NSAssertionHandler : NSObject {
  197.     @private
  198.     void *_reserved;
  199. }
  200.  
  201. + (NSAssertionHandler *)currentHandler;
  202.  
  203. - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName lineNumber:(int)line description:(NSString *)format,...;
  204.  
  205.  
  206. - (void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(int)line description:(NSString *)format,...;
  207.  
  208.  
  209. @end
  210.