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

  1. /* @(#)Z 1.9 com/src/pubutils/include/ODExcept.h, odpubutils, od96os2, odos29646d 96/11/15 15:52:18 (96/10/29 09:28:35) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odpubutils
  6.  *
  7.  *   CLASSES: none
  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. // New exception model. (RobC)
  30.  
  31. #ifndef _ODEXCEPT_
  32. #define _ODEXCEPT_
  33.  
  34. #ifdef __cplusplus           // This file is only valid in the C++ environment
  35.  
  36. #ifndef _ODTYPES_
  37. #include "ODTypes.h"
  38. #endif
  39.  
  40.  
  41. #ifndef _ERRORDEF_
  42.     #include "ErrorDef.xh"    // Clients probably need the error codes as well
  43. #endif
  44.  
  45. #ifndef _ODMVCLNK_
  46. #include <ODMvcLnk.h>
  47. #endif
  48.  
  49. #ifdef _OD_IMPL_SHARE_UTILS_
  50. #pragma import on
  51. #endif
  52.  
  53. // you can use the macros below instead of calling directly.
  54. _DLLIMPORTEXPORT_ void ODSetErrorCode( Environment *, ODException &, ODError); 
  55.  
  56. extern "C" {
  57.  
  58. //=========================================================
  59. // Exception Handling Macros (native C++ exceptions)
  60. //=========================================================
  61. // Programmer note.  These macros assume that the exception that
  62. // has been caught is called: _exception.  That is, you should have
  63. // a catch block that looks something like this:
  64. //  catch(ODException _exception)
  65. //     etc., etc.
  66.  
  67.  
  68. #define ErrorCode()                (_exception.error)
  69. #define ErrorMessage()            (_exception.message)
  70. #define SetErrorMessage(MSG)    (strcpy(_exception.message,(MSG))
  71.  
  72. // this will update the global som ev exception flag
  73. #define SetErrorCode(ERR)        (ODSetErrorCode(kODNULL, _exception, (ERR)))    
  74.  
  75. // this will update the som ev exception flag that is passed in
  76. #define SetErrorCodeEv(EV, ERR)     (ODSetErrorCode(EV, _exception, (ERR)))    
  77.  
  78. // we should consider removing this macro.
  79. #define SET_SOM_EXCEPTION(EV)    ODSetSOMException(EV,_exception);
  80.  
  81.  
  82. //=========================================================
  83. // Raising Exceptions
  84. //=========================================================
  85.  
  86. _DLLIMPORTEXPORT_ void THROW(ODError error);
  87. _DLLIMPORTEXPORT_ void THROW_IF_ERROR(ODError error);
  88. _DLLIMPORTEXPORT_ void THROW_IF_NULL(void* value);
  89.  
  90. // Optional message parameters (ignored in nondebug build):
  91. #if defined(DEBUG)
  92. _DLLIMPORTEXPORT_ void THROW_IF_ERROR_M(ODError error, const char* msg);
  93. _DLLIMPORTEXPORT_ void THROW_M(ODError error, const char* msg);
  94. _DLLIMPORTEXPORT_ void THROW_IF_NULL_M(void* value, const char* msg);
  95. #else
  96. #define THROW_IF_ERROR_M(ERR,MSG)    THROW_IF_ERROR(ERR)
  97. #define THROW_M(ERR,MSG)            THROW(ERR)
  98. #define THROW_IF_NULL_M(ERR,MSG)    THROW_IF_NULL(ERR)
  99. #endif
  100.  
  101. // The following functions operate the same in debug mode and non-debug mode.
  102. // The following functions are the same as the above THROW_M, THROW_IF_ERROR_M,
  103. // and THROW_IF_NULL_M functions when debugging tools are enabled.
  104. // When the debugging tools are not enabled, the following functions allow the
  105. // created exceptions to contain messages while the THROW_M, THROW_IF_ERROR_M,
  106. // and THROW_IF_NULL_M macros discard the passed in message and do not include
  107. // the messages in the created exceptions. 
  108. _DLLIMPORTEXPORT_ void THROW_IF_ERROR_MSG(ODError error, const char* msg);
  109. _DLLIMPORTEXPORT_ void THROW_MSG(ODError error, const char* msg);
  110. _DLLIMPORTEXPORT_ void THROW_IF_NULL_MSG(void* value, const char* msg);
  111. }
  112. // Overloaded C++ equivalents:
  113. inline void THROW_IF_ERROR(ODError error, const char* msg)
  114.                        {THROW_IF_ERROR_M(error,msg);}
  115. inline void THROW(ODError error, const char* msg)
  116.                                {THROW_M(error,msg);}
  117. inline void THROW_IF_NULL(void* value, const char* msg)
  118.                                {THROW_IF_NULL_M(value,msg);}
  119. inline void THROW_IF_NULL(void* value, ODError error)
  120.                                {if ( value == kODNULL ) THROW(error);}
  121. extern "C" {
  122.  
  123. #ifdef _PLATFORM_MACINTOSH_
  124. // Call BreakOnThrow(TRUE) to break into the debugger whenever THROW is called.
  125. // (The call returns the previous value of the setting.)
  126. ODBoolean BreakOnThrow( ODBoolean brk );
  127. #endif
  128.  
  129.  
  130. // ODSetSOMException stores an OD error code in the environment.
  131. // ODGetSOMException returns the OD error code (if any) from an environment.
  132.  
  133. _DLLIMPORTEXPORT_ void    ODSetSOMException( Environment*, ODError, const char *msg =kODNULL );
  134. } // end extern C
  135. _DLLIMPORTEXPORT_ void    ODSetSOMException( Environment*, ODException& );
  136.  
  137. extern "C" {
  138.  
  139. _DLLIMPORTEXPORT_ ODError    ODGetSOMException( Environment *ev );
  140.  
  141. // CHECK_ENV throws an exception if the environment indicates an error.
  142. _DLLIMPORTEXPORT_ void    CHECK_ENV( Environment* );
  143.  
  144. // SOMCHKEXCEPT is a macro that is called in a .xh file if the ev variable
  145. // indicates an exception is set.
  146. #define SOMCHKEXCEPT {CHECK_ENV(ev);}
  147.  
  148.  
  149. } // end extern C
  150. #ifdef _OD_IMPL_SHARE_UTILS_
  151. #pragma import off
  152. #endif
  153.  
  154.  
  155. #endif // __cplusplus
  156. #endif // _ODEXCEPT_
  157.