Exception.h

Go to the documentation of this file.
00001 //
00002 // $Id: Exception.h,v 1.8 2007/03/08 19:59:21 will_mason Exp $
00003 //
00004 // vi: set ft=objc:
00005 
00006 /*
00007  * ObjectiveLib - a library of containers and algorithms for Objective-C
00008  *
00009  * Copyright (c) 2004-2007
00010  * Will Mason
00011  *
00012  * Portions:
00013  *
00014  * Copyright (c) 1994
00015  * Hewlett-Packard Company
00016  *
00017  * Copyright (c) 1996,1997
00018  * Silicon Graphics Computer Systems, Inc.
00019  *
00020  * Copyright (c) 1997
00021  * Moscow Center for SPARC Technology
00022  *
00023  * Copyright (c) 1999 
00024  * Boris Fomitchev
00025  *
00026  * This library is free software; you can redistribute it and/or
00027  * modify it under the terms of the GNU Lesser General Public
00028  * License as published by the Free Software Foundation; either
00029  * version 2.1 of the License, or (at your option) any later version.
00030  *
00031  * This library is distributed in the hope that it will be useful,
00032  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00033  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00034  * Lesser General Public License for more details.
00035  *
00036  * You should have received a copy of the GNU Lesser General Public
00037  * License along with this library; if not, write to the Free Software
00038  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00039  *
00040  * You may contact the author at will_mason@users.sourceforge.net.
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

ObjectiveLibGenerated Sun Apr 22 15:17:58 2007, © 2004-2007 Will Mason
SourceForge.net Logo