home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / EXCEPT.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  7KB  |  230 lines

  1. /* @(#)Z 1.11 com/src/pubutils/include/Except.h, odpubutils, od96os2, odos29646d 96/11/15 15:29:12 (96/10/29 09:28:30) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odpubutils
  6.  *
  7.  *   CLASSES:   Destructo
  8.  *
  9.  *   ORIGINS: 82,27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *       
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. #if ((defined (_PLATFORM_WIN32_) || defined (_PLATFORM_OS2_)) \
  30.       || defined (_PLATFORM_AIX_) ) 
  31. //  Programmers note:  The non-native (aka emulated) exception portion
  32. //  of the ifdefs have been removed for clarity.  Therefore, the code
  33. //  that remains should be regarded as #ifdef _NATIVE_EXCEPTIONS_.
  34. #endif
  35. /*
  36.     File:        Except.h
  37.  
  38.     Contains:    Exception handling macros
  39.  
  40.     Owned by:    Jens Alfke
  41.  
  42.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  43.  
  44. */
  45.  
  46.  
  47. /*
  48.     THEORY OF OPERATION
  49.     
  50.     This is a catch/throw based exception handling package which models
  51.     much of the behavior of native C++ exception handling. (Its macros can
  52.     be redefined to use native exceptions if your compiler supports them.)
  53.     
  54.     Reading this header is not recommended for the faint of heart! Here be
  55.     gnarly macros, setjmp fu, and tangled #ifdefs.
  56.     Please see the recipe document "Using Exceptions" for details presented
  57.     in a human-readable fashion.
  58.     
  59.     If the symbol _NATIVE_EXCEPTIONS_ is predefined, native C++ exception
  60.     handling will be used.
  61.     If the symbol _ASM_XTRY_ is predefined, a special assembly-coded
  62.     version of _xTry will be called, which makes the calling code for TRY
  63.     shorter and slightly faster. (This feature still in progress...)
  64. */
  65.  
  66. #ifndef _EXCEPT_
  67. #define _EXCEPT_
  68.  
  69. #ifndef _ODEXCEPT_
  70. #include "ODExcept.h"
  71. #endif
  72.  
  73. #ifndef _ODTYPES_
  74. #include "ODTypes.h"
  75. #endif
  76.  
  77.  
  78. #ifndef _ERRORDEF_
  79.     #ifdef __cplusplus
  80.     #include "ErrorDef.xh"    // Clients probably need the error codes as well
  81.     #else
  82.     #include "ErrorDef.h"
  83.     #endif
  84. #endif
  85.  
  86. #ifdef __LIBRARYMANAGER__
  87. #error "Please don't include both Except.h and LibraryManager.h"
  88. #endif
  89.  
  90.  
  91. #ifdef _OD_IMPL_SHARE_UTILS_
  92. #pragma import on
  93. #endif
  94.  
  95. #ifdef __cplusplus
  96. extern "C" {
  97. #endif
  98.  
  99.  
  100. //=====================================================================================
  101. // ODVolatile
  102. //=====================================================================================
  103.  
  104. // Any variable or parameter that is modified in a TRY block and used in the
  105. // CATCH block must be declared as volatile or it may have an incorrect value
  106. // in the CATCH block.
  107. // Since not all compilers support the 'volatile' keyword, use this instead;
  108.  
  109. #ifndef _NATIVE_EXCEPTIONS_
  110. // removed. (RobC)
  111. #else
  112. #define ODVolatile(x)    /*no need for this with native exceptions*/
  113. #endif
  114.  
  115. //=====================================================================================
  116. // Exception Handling Macros (native C++ exceptions)
  117. //=====================================================================================
  118.  
  119. #ifdef _NATIVE_EXCEPTIONS_
  120.  
  121. #define TRY                                                    \
  122.                 try {
  123.  
  124. #define CATCH_ALL                                            \
  125.                 } catch(ODException _exception) {
  126.  
  127. #define RERAISE                                                \
  128.                 throw
  129.  
  130. #define ENDTRY                                                \
  131.                 }
  132.  
  133. /* CATCH( ) will not work with native exceptions. Don't use it! */
  134.  
  135.  
  136. //=====================================================================================
  137. // Exception Handling Macros (emulated)
  138. //=====================================================================================
  139.  
  140. #else /*not _NATIVE_EXCEPTIONS*/
  141.  
  142. // removed. (RobC)
  143.  
  144.         
  145. #endif /*_NATIVE_EXCEPTIONS*/
  146.  
  147. //=====================================================================================
  148. // Raising Exceptions
  149. //=====================================================================================
  150.  
  151. // see ODExcept.h
  152.  
  153. //=====================================================================================
  154. // SOM Exception Utilities
  155. //=====================================================================================
  156.  
  157. // This modified TRY block should be used in SOM methods. It's just like a
  158. // regular TRY...CATCH_ALL...ENDTRY except that the exception code will be
  159. // stored in the Environment. Needless to say you should _not_ reraise!
  160. // You should also not make any SOM calls after the SOM_ENDTRY, nor declare any
  161. // Destructo objects before the SOM_TRY.
  162.  
  163. #ifdef _NATIVE_EXCEPTIONS_
  164.  
  165. #define SOM_TRY                                                 \
  166.             TRY
  167.             
  168. #define SOM_CATCH_ALL                                            \
  169.             CATCH_ALL {                                            \
  170.                 
  171. #define SOM_ENDTRY                                                \
  172.             } ODSetSOMException(ev,_exception);                    \
  173.             ENDTRY
  174.             
  175. #else /*not _NATIVE_EXCEPTIONS_*/
  176.  
  177. // removed. (RobC)
  178.  
  179. #endif /*_NATIVE_EXCEPTIONS_*/
  180.  
  181.  
  182. //=====================================================================================
  183. // Finally, the Exception Handler (ODExceptionFrame struct)
  184. //=====================================================================================
  185.  
  186.  
  187. #ifndef _NATIVE_EXCEPTIONS_
  188.  
  189. // removed. (RobC)
  190.  
  191.  
  192. #endif /*_NATIVE_EXCEPTIONS_*/
  193.  
  194.  
  195. #ifdef __cplusplus
  196. }    // end of extern "C" block
  197. #endif
  198.  
  199.  
  200. //=====================================================================================
  201. // Destructo, a C++ base class for auto-destruct objects
  202. //=====================================================================================
  203.  
  204. #ifdef __cplusplus
  205.  
  206. class Destructo
  207. {
  208. #ifndef _NATIVE_EXCEPTIONS_
  209. // removed. (RobC)
  210. #endif /*_NATIVE_EXCEPTIONS_*/
  211.  
  212.     static void* operator new( size_t );    // Make it illegal to allocate on heap
  213.                                             // In future could use alloca??
  214.                                             
  215.     private: // disallow these:
  216.     Destructo(const Destructo& );
  217.     void operator=(const Destructo& );
  218.     // Bitwise assigning one destructo to another smashes
  219.     // fPrevDestructo with potentially unpleasant effects.
  220. };
  221.  
  222. #endif /*__cplusplus*/
  223.  
  224. #ifdef _OD_IMPL_SHARE_UTILS_
  225. #pragma import off
  226. #endif
  227.  
  228.  
  229. #endif // _EXCEPT_
  230.