This is NSFuncallException.h in view mode; [Download] [Up]
/* NSFuncallException.h Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea. All rights reserved. Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro> This file is part of libFoundation. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. We disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall we be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. */ #ifndef __NSException_h__ #define __NSException_h__ #include <setjmp.h> #include <stdarg.h> #include <Foundation/NSString.h> #include <Foundation/NSArray.h> @class NSDictionary; @interface NSException : NSObject { NSString* name; NSString* reason; NSDictionary* userInfo; } /* Creating and Raising Exceptions */ + (NSException*)exceptionWithName:(NSString*)name reason:(NSString*)reason userInfo:(NSDictionary*)userInfo; + (void)raise:(NSString *)name format:(NSString *)format,...; + (void)raise:(NSString*)name format:(NSString*)format arguments:(va_list)argList; - (id)initWithName:(NSString*)name reason:(NSString*)reason userInfo:(NSDictionary*)userInfo; - (void)raise; /* Querying Exceptions */ - (NSString*)name; - (NSString*)reason; - (NSDictionary*)userInfo; @end /* NSException */ @interface NSException (Extensions) - (BOOL)exceptionIsKindOfClass:(Class)class; /* return [self isKindOfClass:class] */ - (BOOL)exceptionIsIn:(NSArray*)exceptions; - (NSString*)errorString; - initWithFormat:(NSString*)format, ...; - initWithFormat:(NSString*)format arguments:(va_list)ap; - setName:(NSString*)name; - setReason:(NSString*)reason; - setUserInfo:(NSDictionary*)userInfo; @end /* NSException (Extension) */ typedef void NSUncaughtExceptionHandler(NSException *exception); NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void); void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *handler); /* Exception names */ extern NSString *NSInconsistentArchiveException; extern NSString *NSGenericException; extern NSString *NSInternalInconsistencyException; extern NSString *NSInvalidArgumentException; extern NSString *NSMallocException; extern NSString *NSRangeException; /* OpenStep macros for exception handling. Use the ones defined below instead. */ #define NS_DURING TRY #define NS_HANDLER \ END_TRY \ OTHERWISE #define NS_ENDHANDLER END_CATCH #define NS_VALRETURN(value) \ ({_NSRemoveHandler(&exceptionHandler); handler(nil); return (value);}) #define NS_VOIDRETURN \ ({_NSRemoveHandler(&exceptionHandler); handler(nil); return;}) typedef void (*THandlerFunction)(id); typedef struct _NSHandler { struct _NSHandler* previousHandler; jmp_buf jmpState; THandlerFunction handler; } NSHandler; extern void _NSAddHandler(NSHandler *handler); extern void _NSRemoveHandler(NSHandler *handler); /* * The new macros for handling exceptions. */ #define TRY \ { \ auto void handler(); \ NSHandler exceptionHandler; \ \ int _dummy = \ ({ \ __label__ _quit; \ if(!setjmp(exceptionHandler.jmpState)) { \ exceptionHandler.handler = handler; \ _NSAddHandler(&exceptionHandler); #define END_TRY \ _NSRemoveHandler(&exceptionHandler); \ handler(nil); \ goto _quit; /* to remove compiler warning about unused label*/ \ }; \ _quit: 0; \ }); \ void handler(NSException* localException) \ { \ BOOL _caught = NO; \ if(localException) \ _NSRemoveHandler(&exceptionHandler); \ if(!localException) { _dummy++; #define CATCH(exception_class) \ } else if([localException exceptionIsKindOfClass:[exception_class class]]) { \ _caught = YES; #ifndef PRECOMP # define MULTICATCH(exception_classes...) \ } else if([localException exceptionIsIn: \ [NSArray arrayWithObjects:##exception_classes, nil]]) { \ _caught = YES; #endif /* PRECOMP */ #define OTHERWISE \ } else { \ _caught = YES; #define CLEANUP \ } \ if(localException && !_caught) { #define FINALLY \ } \ if(1) { #define END_CATCH \ } \ if(!localException) return; \ if(!_caught) \ [localException raise]; \ else {\ [localException release]; \ longjmp(exceptionHandler.jmpState, 1); \ }\ } \ } /* Use BREAK inside a TRY block to get out of it */ #define BREAK ({_NSRemoveHandler(&exceptionHandler); goto _quit;}) #ifndef PRECOMP /* If you want to generate an exception issue a THROW with the exception an object derived from the NSException class. */ # define THROW(exception...) [##exception raise] #else # define THROW(exception) [exception raise] #endif /* PRECOMP */ /* If you want to reraise an exception inside an exception handler just say RERAISE. */ #define RERAISE [localException raise] /* * Assertions. */ #ifndef __FoundationException_definition__ #define __FoundationException_definition__ @interface FoundationException : NSException @end #endif /* __FoundationException_definition__ */ @interface AssertException : FoundationException @end @interface NSAssertionHandler : NSObject /* Getting the Current Handler */ + (NSAssertionHandler*)currentHandler; /* Handling Failures */ - (void)handleFailureInFunction:(NSString*)functionName file:(NSString*)fileName lineNumber:(int)line description:(NSString*)format,...; - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString*)fileName lineNumber:(int)line description:(NSString*)format,...; @end #ifndef PRECOMP # define NSAssert(condition, desc, arguments...) \ ({ if(!(condition)) \ [[NSAssertionHandler currentHandler] \ handleFailureInMethod:_cmd \ object:self \ file:[NSString stringWithCString:__FILE__] \ lineNumber:__LINE__ \ description:(desc) , ##arguments]; \ 0;}) # define NSCAssert(condition, desc, arguments...) \ ({ if(!(condition)) \ [[NSAssertionHandler currentHandler] \ handleFailureInFunction: \ [NSString stringWithCString:__PRETTY_FUNCTION__] \ file:[NSString stringWithCString:__FILE__] \ lineNumber:__LINE__ \ description:(desc) , ##arguments]; \ 0;}) # define Assert(condition) \ ({if(!(condition)) {\ NSLog([(@#condition) stringByPrependingString:@"Assertion failed: "]); \ THROW([AssertException new]); \ } \ 0;}) # define NSAssert1(args...) NSAssert(##args) # define NSAssert2(args...) NSAssert(##args) # define NSAssert3(args...) NSAssert(##args) # define NSAssert4(args...) NSAssert(##args) # define NSAssert5(args...) NSAssert(##args) # define NSCAssert1(args...) NSCAssert(##args) # define NSCAssert2(args...) NSCAssert(##args) # define NSCAssert3(args...) NSCAssert(##args) # define NSCAssert4(args...) NSCAssert(##args) # define NSCAssert5(args...) NSCAssert(##args) #endif /* PRECOMP */ #endif /* __NSException_h__ */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.