00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #if !defined(EXCEPTION_OL_GUARD)
00044 #if !defined(OL_GENERATING_DOCUMENTATION)
00045 #define EXCEPTION_OL_GUARD
00046 #endif
00047
00048 #include <ObjectiveLib/ObjectBase.h>
00049
00148 #if defined(OL_NO_OPENSTEP)
00149 extern OLConstantString* const OLInputOutputException;
00150 #else
00151 extern NSString* const OLInputOutputException;
00152 #endif
00153
00157 #if defined(OL_NO_OPENSTEP)
00158 extern OLConstantString* const OLEndOfStreamException;
00159 #else
00160 extern NSString* const OLEndOfStreamException;
00161 #endif
00162
00166 #if defined(OL_NO_OPENSTEP)
00167 extern OLConstantString* const OLSocketException;
00168 #else
00169 extern NSString* const OLSocketException;
00170 #endif
00171
00175 #if defined(OL_NO_OPENSTEP)
00176 extern OLConstantString* const OLClassNotFoundException;
00177 #else
00178 extern NSString* const OLClassNotFoundException;
00179 #endif
00180
00181 #if defined(OL_NO_OPENSTEP)
00182
00183 #include <setjmp.h>
00184 #include <stdarg.h>
00185
00189 extern OLConstantString* const OLInvalidArgumentException;
00190
00195 extern OLConstantString* const OLGenericException;
00196
00204 @interface OLException : Object
00205 {
00206 @protected
00210 char* type;
00211
00215 char* message;
00216 }
00217
00226 + (void) raiseType: (const char*)nm message: (const char*)msg, ...;
00227
00238 + (void) raiseTypeString: (OLConstantString*)nm messageString: (OLConstantString*)msg, ...;
00239
00243
00254 - (id) initWithType: (const char*)nm message: (const char*)msg arguments: (va_list)args;
00255
00265 - (id) initWithType: (const char*)nm message: (const char*)msg, ...;
00266
00270 - (id) free;
00271
00272
00278 - (const char*) message;
00279
00285 - (const char*) type;
00286
00295 - (void) raise;
00296
00297 @end
00298
00310 typedef struct _OLCatchInfo
00311 {
00315 struct _OLCatchInfo* next;
00316
00321 jmp_buf jumpInfo;
00322
00326 OLException* exception;
00327 } OLCatchInfo;
00335 extern void OLPushCatchInfo(OLCatchInfo* info);
00336
00341 extern void OLPopCatchInfo();
00342
00348 #define OL_TRY \
00349 { \
00350 OLCatchInfo __currentCatchInfo; \
00351 OLPushCatchInfo(&__currentCatchInfo); \
00352 if (!setjmp(__currentCatchInfo.jumpInfo)) \
00353 {
00354
00360 #define OL_CATCH \
00361 OLPopCatchInfo(); \
00362 } \
00363 else \
00364 { \
00365 OLException* localException = __currentCatchInfo.exception; \
00366 {
00367
00373 #define OL_END_CATCH \
00374 } \
00375 [localException free]; \
00376 } \
00377 }
00378
00385 #define OL_TRY_RETURN(val) \
00386 { \
00387 typeof(val) __tryReturnValue = val; \
00388 OLPopCatchInfo(); \
00389 return __tryReturnValue; \
00390 }
00391
00397 #define OL_TRY_ABANDON \
00398 OLPopCatchInfo(); \
00399 return;
00400
00407 #define OL_CATCH_RETURN(val) \
00408 { \
00409 typeof(val) __catchReturnValue = val; \
00410 [localException free]; \
00411 return __catchReturnValue; \
00412 }
00413
00419 #define OL_CATCH_ABANDON \
00420 [localException free]; \
00421 return
00422
00434 #define OL_CATCH_RAISE(typ, ...) \
00435 [localException free]; \
00436 [OLException raise: typ message: __VA_ARGS__]
00437
00448 #define OL_CATCH_RAISE_STRING(typ, ...) \
00449 [localException free]; \
00450 [OLException raiseTypeString: typ messageString: __VAR_ARGS__]
00451
00452 #endif
00453
00454 #endif