2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #ifndef __NGExtensions_NSException_misc_H__
23 #define __NGExtensions_NSException_misc_H__
25 #import <Foundation/NSException.h>
26 #import <Foundation/NSLock.h>
29 Miscellaneous method additions to NSException
31 the additions make it easier using exceptions in the Java way. In OpenStep
32 exceptions are identified by their name, subclasses are mainly used when
33 additional information needs to be stored. This works well as long as you do
34 not use exceptions very much (as in the Foundation Kit) - if you do you
35 soon wish to have a 'hierachy' of exceptions. This can be modelled - like in
36 Java - using a subclass for each different kind of exception and then using
37 the type of the exception for it's identification. This is supported by
38 libFoundation using the TRY and CATCH macros.
40 The methods below always use the class name as the exception name if the name
41 isn't specified explicitly.
44 @interface NSException(NGMiscellaneous)
46 - (id)initWithReason:(NSString *)_reason;
47 - (id)initWithReason:(NSString *)_reason userInfo:(id)_userInfo;
48 - (id)initWithFormat:(NSString *)_format,...;
52 @interface NSObject(NSExceptionNGMiscellaneous)
54 - (BOOL)isExceptionOrNull;
58 #if COCOA_Foundation_LIBRARY || GNUSTEP_BASE_LIBRARY
59 @interface NSException (NGLibFoundationCompatibility)
60 - (void)setReason:(NSString *)_reason;
66 The following macros are for use of locks together with exception handling.
67 A synchronized block is properly 'unlocked' even if an exception occures.
70 SYNCHRONIZED(MyObject) {
75 Where MyObject must be an object that conforms to the NSObject and NSLocking
77 This is much different to
85 which leaves the lock locked when an exception happens.
88 #if defined(DEBUG_SYNCHRONIZED)
90 #define SYNCHRONIZED(__lock__) \
92 id<NSObject,NSLocking> __syncLock__ = [__lock__ retain]; \
93 [__syncLock__ lock]; \
94 fprintf(stderr, "0x%08X locked in %s.\n", \
95 (unsigned)__syncLock__, __PRETTY_FUNCTION__); \
98 #define END_SYNCHRONIZED \
101 fprintf(stderr, "0x%08X exceptional unlock in %s exception %s.\n", \
102 (unsigned)__syncLock__, __PRETTY_FUNCTION__,\
103 [[localException description] cString]); \
104 [__syncLock__ unlock]; \
105 [__syncLock__ release]; __syncLock__ = nil; \
106 [localException raise]; \
109 fprintf(stderr, "0x%08X unlock in %s.\n", \
110 (unsigned)__syncLock__, __PRETTY_FUNCTION__); \
111 [__syncLock__ unlock]; \
112 [__syncLock__ release]; __syncLock__ = nil; \
117 #define SYNCHRONIZED(__lock__) \
119 id<NSObject,NSLocking> __syncLock__ = [__lock__ retain]; \
120 [__syncLock__ lock]; \
123 #define END_SYNCHRONIZED \
126 [__syncLock__ unlock]; \
127 [__syncLock__ release]; \
128 [localException raise]; \
131 [__syncLock__ unlock]; \
132 [__syncLock__ release]; \
137 #endif /* __NGExtensions_NSException_misc_H__ */