ftp.nice.ch/pub/next/developer/languages/c/gcc.2.7.2.2.I.b.tar.gz#/lib/gcc-lib/m68k-next-nextstep3/2.7.2.2.f.2/include/foundation/NSException.h

This is NSException.h in view mode; [Download] [Up]

/*	NSException.h
  	Copyright 1994, NeXT, Inc.
	NeXT, April 1994
*/

#import <foundation/NSDictionary.h>
#include <setjmp.h>

/***************	Exception names		***************/

extern NSString *NSGenericException;
extern NSString *NSRangeException;
extern NSString *NSInvalidArgumentException;
extern NSString *NSParseErrorException;
extern NSString *NSInternalInconsistencyException;
extern NSString *NSObjCInadequateRuntimeInformation;

extern NSString *NSCodingException;
extern NSString *NSObjectInaccessibleException;
extern NSString *NSObjectNotAvailableException;
extern NSString *NSDestinationInvalidException;
extern NSString *NSOwnershipTransferException;
    
extern NSString *NSPortTimoutException;
extern NSString *NSInvalidSendPort;
extern NSString *NSInvalidReceivePort;
extern NSString *NSPortSendError;
extern NSString *NSPortReceiveError;
extern NSString *NSPortNameRegistrationError;

extern NSString *NSArchiverArchiveInconsistency;
extern NSString *NSArchiverClassError;
extern NSString *NSArchiverDescriptorError;
extern NSString *NSArchiverWriteReferenceError;

extern NSString *NSDateMissingTimeZone;

/***************	Exception object	***************/

@interface NSException:NSObject <NSCopying> {
    /* Exceptions are immutable, although they may retain objects in a dictionary that may be mutable;
    Note that -description is used when an exception is reported and can be redefined */
    NSString		*name;		/* Exception name */
    NSString		*reason; 	/* Human readable reason for raising */
    NSDictionary	*userInfo;	/* Any arbitrary other data */
}

+ (NSException *)exceptionWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
    /* Creates an autoreleased exception */

- (NSString *)exceptionName;

- (NSString *)exceptionReason;

- (NSDictionary *)exceptionUserInfo;
    /* May return nil */

- (volatile void)raise;
    /* Dispatches according to the appropriate catcher;
    Never returns */

- initWithName:(NSString *)name reason:(NSString *)reason userInfo:(NSDictionary *)userInfo;
    /* Designated initializer */

@end

/***************	Conveniences for raising	***************/

@interface NSException (NSExceptionRaisingConveniences)

+ (volatile void)raise:(NSString *)name format:(NSString *)format, ...;
    /* Create an exception then raise it; 
    format is used to create the exception 'reason' */

+ (volatile void)raise:(NSString *)name format:(NSString *)format arguments:(va_list)argList;

@end

/***************	Raising and catching	***************/

#define NSExceptionBase 100000 /* TEMPORARY!*/
#define NSLastException 100999 /* TEMPORARY!*/

/* Private definition*/
typedef struct _NSHandler {	/* a node in the handler chain */
    jmp_buf		jumpState;	/* place to longjmp to */
    struct _NSHandler	*next;		/* ptr to next handler */
    int 		code;		/* error code of exception; always >=NSExceptionBase and <=NSLastException for now */
    const void		*data1;		/* The exception object */
    const void		*data2;		/* Reserved for compatibility */
} NSHandler;

/* NS_DURING, NS_HANDLER and NS_ENDHANDLER are always used like:

	NS_DURING
	    some code which might raise an error
	NS_HANDLER
	    code that will be jumped to if an error occurs
	NS_ENDHANDLER

   If any error is raised within the first block of code, the second block of code will be jumped to.  Typically, this code will clean up any resources allocated in the routine, possibly case on the error code and perform special processing, and default to -raise again the exception to the next handler.  Within the scope of the handler, a local variable called 'exception' holds the raised exception.
   It is illegal to exit the first block of code by any other means than
   NS_VALRETURN, NS_VOIDRETURN, or just falling out the bottom.
 */

/* private support routines.  Do not call directly. */
extern void _NSAddHandler(NSHandler *handler);
extern void _NSRemoveHandler(NSHandler *handler);
extern _setjmp(jmp_buf env);

#define NS_DURING { NSHandler _localHandler;			\
		    _NSAddHandler(&_localHandler);		\
		    if( !_setjmp(_localHandler.jumpState) ) {

#define NS_HANDLER _NSRemoveHandler(&_localHandler); } else { \
		    NSException	*exception = (_localHandler.code >= NSExceptionBase && _localHandler.code <= NSLastException) ? (id)_localHandler.data1 : nil;

#define NS_ENDHANDLER exception = nil; /* to avoid compiler warning */}}

#define NS_VALRETURN(val)  do { typeof(val) temp = (val);	\
			_NSRemoveHandler(&_localHandler);	\
			return(temp); } while (0)

#define NS_VOIDRETURN	do { _NSRemoveHandler(&_localHandler);	\
			return; } while (0)

/***************	Changing the top level error catcher	***********/

/* The top level error catcher can be set to look for certain exceptions, do some work, and then either abort or call the previous top level error catcher */

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

extern NSUncaughtExceptionHandler *NSGetUncaughtExceptionHandler(void);
extern void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *);

/***********	Assertion of program consistency		***********/

/* Assertions evaluate a condition, and if it is false, they call the NSAssertionHandler for the current thread to report that fact.  The assertion macros also take a "description" argument, which should describe the failure that is being tested for.  The description is a printf-style format NSString.  N args may be passed using the NSAssertN() variations.  When calling from within a method, the object's class and method name need not be included in the description, since those args are passed separately.

Assertions are compiled into code if the cpp macro NS_BLOCK_ASSERTIONS is defined.  Runtime control is achieved by substituting a different assertion handler.

Since these macros pass the variables "self" and "_cmd" automatically, they assume that they are being called from within a method context. There is a parallel set of macros for use within C functions. 
*/


@class NSAssertionHandler;

/* Implementation of asserts (ignore) */
#ifdef NS_BLOCK_ASSERTIONS
#define _NSAssertBody(condition, desc, arg1, arg2, arg3)	\
    do {						\
	if (!(condition)) {				\
	    [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithCString:__FILE__] lineNumber:__LINE__ description:(desc), (arg1), (arg2), (arg3)];	\
	}						\
    } while(0)
#define _NSCAssertBody(condition, desc, arg1, arg2, arg3)	\
    do {						\
	if (!(condition)) {				\
	    [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__] file:[NSString stringWithCString:__FILE__] lineNumber:__LINE__ description:(desc), (arg1), (arg2), (arg3)];	\
	}						\
    } while(0)
#else
#define _NSAssertBody(condition, desc, arg1, arg2, arg3)
#define _NSCAssertBody(condition, desc, arg1, arg2, arg3)
#endif


/*
 * Asserts to use in Objective-C method bodies
 */
 
#define NSAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5)	\
    _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))

#define NSAssert4(condition, desc, arg1, arg2, arg3, arg4)	\
    _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4))

#define NSAssert3(condition, desc, arg1, arg2, arg3)	\
    _NSAssertBody((condition), (desc), (arg1), (arg2), (arg3))

#define NSAssert2(condition, desc, arg1, arg2)		\
    _NSAssertBody((condition), (desc), (arg1), (arg2), 0)

#define NSAssert1(condition, desc, arg1)		\
    _NSAssertBody((condition), (desc), (arg1), 0, 0)

#define NSAssert(condition, desc)			\
    _NSAssertBody((condition), (desc), 0, 0, 0)

/* convenience for validating parameters.  The text of the condition that fails is passed to the handler. */
#define NSParameterAssert(condition)			\
    _NSAssertBody((condition), @"Invalid parameter not satisfying: %s", #condition, 0, 0)

/*
 * Asserts to use in C function bodies
 */
 
#define NSCAssert5(condition, desc, arg1, arg2, arg3, arg4, arg5)	\
    _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4), (arg5))

#define NSCAssert4(condition, desc, arg1, arg2, arg3, arg4)	\
    _NSCAssertBody((condition), (desc), (arg1), (arg2), (arg3), (arg4))

#define NSCAssert3(condition, desc, arg1, arg2, arg3)	\
    _NSCAssertBody((condition), (desc), (arg1), (arg2), arg3)

#define NSCAssert2(condition, desc, arg1, arg2)	\
    _NSCAssertBody((condition), (desc), (arg1), (arg2), 0)

#define NSCAssert1(condition, desc, arg1)		\
    _NSCAssertBody((condition), (desc), (arg1), 0, 0)

#define NSCAssert(condition, desc)			\
    _NSCAssertBody((condition), (desc), 0, 0, 0)

/* convenience for validating parameters.  The text of the condition that fails is passed to the handler. */
#define NSCParameterAssert(condition)			\
    _NSCAssertBody((condition), @"Invalid parameter not satisfying: %s", #condition, 0, 0)


@interface NSAssertionHandler : NSObject

+ (NSAssertionHandler *)currentHandler;

- (void)handleFailureInMethod:(SEL)selector object:object file:(NSString *)fileName lineNumber:(int)line description:(NSString *)format,...;

- (void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(int)line description:(NSString *)format,...;

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.