ftp.nice.ch/Attic/openStep/implementation/gnustep/sources/libFoundation.0.7.tgz#/libFoundation-0.7/FoundationExtensions/extensions/gnustep-base/NSException.h

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

/* 
   Copyright (C) 1996 
	Ovidiu Predescu <ovidiu@bx.logicnet.ro>
	Mircea Oancea <mircea@jupiter.elcom.pub.ro>

   Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>

   This file is part of the FoundationExtensions library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __NSException_h__
#define __NSException_h__

#include <Foundation/NSException.h>
#include <Foundation/NSArray.h>

@interface NSException (Extensions)
- (BOOL)exceptionIsKindOfClass:(Class)class;
				/* return [self isKindOfClass:class] */
- (BOOL)exceptionIsIn:(NSArray*)exceptions;
- (NSString*)errorString;
- initWithFormat:(NSString*)format, ...;
- setName:(NSString*)name;
- setReason:(NSString*)reason;
- setUserInfo:(NSDictionary*)userInfo;
@end /* NSException (Extension) */


/*
 * The new macros for handling exceptions.
 */

#define TRY \
({ \
    __label__ _quit; \
    NSHandler exceptionHandler; \
    int __setjmp_ret = setjmp(exceptionHandler.jumpState); \
    if(!__setjmp_ret) { \
	_NSAddHandler(&exceptionHandler);

#define END_TRY \
	_NSRemoveHandler(&exceptionHandler); \
	goto _quit; /* to remove compiler warning about unused label*/ \
    } \
_quit: \
    { \
	void handler(id localException) \
	{ \
	    BOOL _caught = NO; \
	    if(!localException) {

#define CATCH(exception_class) \
	    } else if([localException isKindOfClass:[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]; \
	} \
	handler(__setjmp_ret == 1 ? exceptionHandler.exception : nil); \
    } \
});

    /*  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                 THROW(localException)


/*
 * Assertions.
 */

#ifndef __FoundationException_definition__
#define __FoundationException_definition__

@interface FoundationException : NSException
@end

#endif /* __FoundationException_definition__ */

@interface AssertException : FoundationException
@end


#ifndef PRECOMP

#define Assert(condition) \
    ({if(!(condition)) {\
	NSLog([@"Assertion failed: " stringByAppendingString:(@#condition)]); \
	THROW([AssertException new]); \
    } \
    0;})

#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.