home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PUBUTILS / EXCEPT.H < prev    next >
Text File  |  1995-12-04  |  6KB  |  148 lines

  1. /********************************************************************/
  2. /*  Licensed Materials - Property of IBM                            */
  3. /*                                                                  */
  4. /*                                                                  */
  5. /* Copyright (C) International Business Machines Corp., 1994.       */
  6. /* Copyright (C) Apple Computer, Inc., 1994                         */
  7. /*                                                                  */
  8. /*  US Government Users Restricted Rights -                         */
  9. /*  Use, duplication, or disclosure restricted                      */
  10. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  11. /*                                                                  */
  12. /*  OpenDoc C++ macros for handling SOM Exceptions.  Be sure to     */
  13. /*  include this file BEFORE any .xh file because the bindings      */
  14. /*  use the SOMCHKEXCEPT macro defined here.                        */
  15. /*                                                                  */
  16. /********************************************************************/
  17.  
  18. #ifndef _EXCEPT_
  19. #define _EXCEPT_
  20.  
  21. #ifndef INCL_ODDTS // include non-DTS C++ headers
  22.  
  23. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  24. #include "ODTypesB.xh"
  25. #endif
  26.  
  27. #ifndef _ERRORDEF_
  28. #include "ErrorDef.xh"  // Clients probably need the error codes as well
  29. #endif
  30.  
  31. #else // include DTS C++ headers
  32.  
  33. #ifndef SOM_HH_DTS_Included
  34. #include <som.hh>
  35. #endif
  36. #ifndef _DTS_HH_INCLUDED_ODTypesB
  37. #include <ODTypesB.hh>
  38. #endif
  39. #ifndef _DTS_HH_INCLUDED_ErrorDef
  40. #include <ErrorDef.hh>
  41. #endif
  42.  
  43. #endif // ! INCL_ODDTS
  44.  
  45. const char* ODGetErrorStringRep(ODError err);  // returns the string rep of the err code
  46.  
  47. //=====================================================================================
  48. // Exception Handling Macros (native C++ exceptions)
  49. //=====================================================================================
  50.  
  51. class ODNativeException {
  52.   ODError fError;
  53.   char* fMessage;
  54.   Environment* fEv;
  55. public:
  56.   ODNativeException(ODError error, const char* msg);
  57.   ODNativeException(const ODNativeException& x);
  58.   ~ODNativeException();
  59.   int error() const {return fError;}
  60.   const char* message() const {return fMessage;}
  61.   void SetEnvironmentPtr( Environment *ev ) { fEv = ev; }
  62. };
  63. #define ErrorCode()       (_exception.error())
  64. #define ErrorMessage()      (_exception.message())
  65.  
  66. #define TRY                         \
  67.         try { 
  68.  
  69. #define CATCH_ALL                     \
  70.         } catch(ODNativeException _exception) { 
  71.  
  72. #define RERAISE                       \
  73.         throw
  74.  
  75. #define ENDTRY                        \
  76.             }
  77.  
  78.  
  79. //=====================================================================================
  80. // Raising Exceptions
  81. //=====================================================================================
  82.  
  83. #ifdef _PLATFORM_OS2_PPC_  /*PPC-@SK*/
  84. #define __FUNCTION__  ""   /* CED */
  85. #endif
  86. #if ODDebug
  87. #define __XFILE__     __FILE__
  88. #define __XFUNCTION__ __FUNCTION__
  89. #define __XLINE__     __LINE__
  90. #else
  91. #define __XFILE__     0
  92. #define __XFUNCTION__ 0
  93. #define __XLINE__     0
  94. #endif
  95.  
  96. void THROWproc(ODError, const char*, int, const char*, const char*);
  97. #define THROW_IF_ERROR(a)      THROW_IF_ERROR_M((a), kODNULL)
  98. #define THROW_IF_NULL(a)       THROW_IF_NULL_M((a), kODNULL)
  99. #define THROW(a)               THROW_M((a), kODNULL)
  100. #define THROW_IF_ERROR_M(a,b)  if (a) {THROWproc((a), (b), __XLINE__, __XFUNCTION__, __XFILE__ );} else {}
  101. #define THROW_IF_NULL_M(a,b)   if (!(a)){THROWproc(kODErrOutOfMemory,(b), __XLINE__, __XFUNCTION__, __XFILE__ );} else {}
  102. #define THROW_M(a,b)           THROWproc((a),(b),  __XLINE__, __XFUNCTION__, __XFILE__ )
  103.  
  104. // These macros should be used to raise an OpenDoc SOM exception without causing
  105. // transfer of control to a catch handler.  These macros do essentially the same
  106. // thing as ODSetSOMException, with the added feature of logging the location
  107. // (line #, function & filename) where the exception was raised.
  108.  
  109. void RAISEproc(Environment*, ODError, const char*, int, const char*, const char*);
  110. #define SOM_RAISE(ev, a)             SOM_RAISE_M(ev, (a), kODNULL)
  111. #define SOM_RAISE_M(ev, a, b)        RAISEproc(ev, (a), (b), __XLINE__, __XFUNCTION__, __XFILE__ )
  112.  
  113. //=====================================================================================
  114. // SOM Exception Utilities
  115. //=====================================================================================
  116.  
  117. // This modified TRY block should be used in SOM methods. It's just like a
  118. // regular TRY...CATCH_ALL...ENDTRY except that the exception code will be
  119. // stored in the Environment. Needless to say you should _not_ reraise!
  120.  
  121. #define SOM_TRY                         \
  122.       TRY 
  123.  
  124. #define SOM_CATCH_ALL                     \
  125.       CATCH_ALL                     \
  126.         _exception.SetEnvironmentPtr(ev); 
  127.  
  128. #define SOM_ENDTRY                        \
  129.       ENDTRY 
  130.  
  131. // ODSetSOMException stores an OD error code in the environment.
  132. // ODGetSOMException returns the OD error code (if any) from an environment.
  133.  
  134. void  ODSetSOMException( Environment*, ODError, const char *msg =kODNULL );
  135. void  ODSetSOMException( Environment*, ODNativeException& );
  136. ODError  ODGetSOMException( Environment *ev );
  137.  
  138. const char * ODGetErrStringRep(ODError error);// so docshell can call it. 139921
  139. // CHECK_ENV throws an exception if the environment indicates an error.
  140.  
  141. void  CHECK_ENV( Environment* );
  142.  
  143. // SOMCHKEXCEPT is a macro that is called in a .xh file if the ev variable
  144. // indicates an exception is set.
  145. #define SOMCHKEXCEPT { CHECK_ENV(ev); }
  146.  
  147. #endif // _EXCEPT_
  148.