home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / source / bento / headers / except.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-02  |  4.7 KB  |  155 lines

  1. /*
  2.     File:        Except.h
  3.  
  4.     Contains:    Exception handling macros
  5.  
  6.     Written by:    Richard Rodseth, Steve Smith, Jens Alfke
  7.  
  8.     Copyright:    ⌐ 1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <18>      2/9/94    NP        Tiger Team cleanup.
  13.         <17>      2/7/94    JA        Capitalized THROW functions.
  14.         <16>      2/7/94    JA        Tiger Team Makeover!
  15.         <15>     1/31/94    JA        Made assertions no-ops in non debug builds.
  16.                                     Added logging functions.
  17.         <14>     12/3/93    Té        Rename XMPError.h to ErrorDef.h
  18.         <13>     9/22/93    JA        Made new assertion macros.
  19.         <12>      9/8/93    NP        Put back LibraryManager.h. GRRRRRRR.
  20.         <11>      9/8/93    SS        Removed stream class includes; moved stdio
  21.                                     includes to .cp
  22.         <10>     8/25/93    SS        Moved functions to Except.cp - added
  23.                                     constants for new logging functionality
  24.          <9>      7/12/93    RCR        Added XMPVolatile.
  25.          <8>     6/18/93    RCR        Added ThrowIfNULL and Throw.
  26.          <7>     6/15/93    VL        Made ThrowIfError an inline.
  27.          <3>     6/11/93    RCR        Added ASSERT Macro
  28.          <2>     6/10/93    RCR        Change to new SLM Exception macros
  29.          <1>     6/10/93    RCR        first checked in
  30.  
  31.     To Do:
  32. */
  33.  
  34.  
  35. /*
  36.     THEORY OF OPERATION
  37.     
  38.     To come. See LibraryManager.h
  39.     
  40.     This file simply uses the Apple Shared Library Manager exceptions.
  41.  
  42.     Example Usage:
  43.     
  44.         XMPFoo* obj = kXMPNULL;
  45.         XMPVolatile(obj);            // if it's modified in TRY, and used in CATCH
  46.                                 // it must be kept out of registers
  47.         
  48.         TRY
  49.         
  50.             obj = new XMPFoo;
  51.             FailNULL(obj, kXMPErrOutOfMemory);    // Until global new throws exception
  52.             obj->Initialize();    // Initialization that can fail
  53.         
  54.         CATCH(kXMPErrOutOfMemory)
  55.         
  56.             DeleteObject(&obj);        // i.e. if (obj) { delete obj; obj == NULL }
  57.         
  58.         CATCH_ALL
  59.         
  60.             // Do some stuff
  61.             RERAISE; // or: Fail(error);
  62.                     
  63.         ENDTRY
  64.     
  65.     Limitations: 
  66.         One Exception type (a long integer value)
  67.         Catch block must rethrow errors it doesn't handle
  68.         No automatic calling of destructors
  69.         Use of VOLATILE (See below)
  70.         Maybe some others
  71.     
  72. */
  73.  
  74. //
  75. //--------------------------------------<< Ñ >>--------------------------------------
  76.  
  77. #ifndef _EXCEPT_
  78. #define _EXCEPT_
  79.  
  80. #ifndef _XMPTYPES_
  81. #include "XMPTypes.h"
  82. #endif
  83.  
  84. #ifndef _ERRORDEF_
  85. #include "ErrorDef.h"
  86. #endif
  87. // ErrorDef.h is included here as a convenience
  88. // if you are including Except.h in order to throw exceptions, 
  89. // you probably need the exception codes as well.
  90. // -Tantek éelik (93.12.03)
  91.  
  92. #ifndef __LIBRARYMANAGER__
  93. #include <LibraryManager.h>
  94. #endif
  95.  
  96.  
  97. #define XMPVolatile(x) Volatile(x)
  98.  
  99. #define exceptionMask    0x0000FFFF
  100. #define methodMask        0x00FF0000
  101. #define classMask        0xFF000000
  102.  
  103. #define kExceptionList    100
  104. #define kClassList        101
  105.  
  106. void WriteToFile( char* expType = kXMPNULL, XMPError error = 0, char* msg = kXMPNULL);
  107. void THROW_IF_ERROR(XMPError error, char* msg = kXMPNULL);
  108. void THROW(XMPError error, char* msg = kXMPNULL);
  109. void THROW_IF_NULL(void* value, char* msg = kXMPNULL);
  110.  
  111. // Logging.
  112. // LOG has the same syntax as printf but produces a SysBreakStr, which will
  113. // write the result to the log window in VoodooMonkey. (It will also cause
  114. // a breakpoint, unfortunately.) You should put a "\n" at the end of the
  115. // format string if you want to end the line there.
  116. //
  117. // To enable logging in a source file, you must redefine the symbol LOGGING
  118. // as "1" in that file, otherwise LOG statements will not be compiled. Make
  119. // sure to #undef the symbol before you re-#define it, as some compilers
  120. // (e.g. Symantec) won't redefine an already-defined symbol.
  121. //
  122. // LOG statements do not generate any code if logging is off.
  123.  
  124. #define LOGGING 0        // Redefine as 1 in source file to enable logging
  125.  
  126. #define LOG        if(!XMPDebug || !LOGGING) ; else _Log
  127.  
  128. // Warnings.
  129. // WARN has the same syntax as printf but produces a SysBreakStr.
  130. // Warnings are disabled (and generate no code) when XMPDebug is off.
  131.  
  132. #define WARN    if(!XMPDebug) ; else _Warn
  133.  
  134. // Assertion macros.
  135. // These all cause a SysBreakStr if the condition evaluates to false or 0.
  136. // Leading "W" is a Warning: it doesn't raise an exception.
  137. // Trailing "M" means special Message displayed instead of condition.
  138.  
  139. #define ASSERT( COND, ERR )    \
  140.     if(!XMPDebug || (COND)) ; else _AssertionFailed( #COND, __FILE__, ERR )
  141. #define ASSERTM( COND, ERR, MSG )    \
  142.     if(!XMPDebug || (COND)) ; else _AssertionFailed( #COND, __FILE__, ERR, MSG )
  143. #define WASSERT( COND )    \
  144.     if(!XMPDebug || (COND)) ; else _AssertionFailed( #COND, __FILE__, 0)
  145. #define WASSERTM( COND, MSG )    \
  146.     if(!XMPDebug || (COND)) ; else _AssertionFailed( #COND, __FILE__, 0, MSG)
  147.  
  148. // Functions that underly these macros:
  149. void _Log                ( char *fmt, ... );
  150. void _Warn                ( char *fmt, ... );
  151. void _AssertionFailed    ( char *cond,  char *fileName,
  152.                             XMPError, char *msg = kXMPNULL );
  153.  
  154. #endif // _EXCEPT_
  155.