home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWODExce / FWODExce.cpp next >
Encoding:
Text File  |  1996-09-17  |  5.5 KB  |  191 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWODExce.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef _ERRORDEF_
  13. #include "ErrorDef.xh"
  14. #endif
  15.  
  16. #ifndef FWODEXCE_H
  17. #include "FWODExce.h"
  18. #endif
  19.  
  20. #ifndef FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  25. #include "ODTypesB.xh"
  26. #endif
  27.  
  28. #include <new.h>
  29.  
  30. //========================================================================================
  31. //    Runtime Informations
  32. //========================================================================================
  33.  
  34. #ifdef FW_BUILD_MAC    
  35. #pragma segment slexcept
  36. #endif
  37.  
  38. //========================================================================================
  39. // Global functions
  40. //========================================================================================
  41.  
  42. //----------------------------------------------------------------------------------------
  43. //    FW_FailOnError
  44. //----------------------------------------------------------------------------------------
  45.  
  46. void FW_FailOnError(FW_PlatformError error)
  47. {
  48.     if (error != 0)
  49.         FW_THROW(FW_XException(error));
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    FW_Failure
  54. //----------------------------------------------------------------------------------------
  55.  
  56. void FW_Failure(FW_PlatformError error)
  57. {
  58.     FW_ASSERT(error != 0);
  59.     FW_THROW(FW_XException(error));
  60. }
  61.  
  62. //----------------------------------------------------------------------------------------
  63. // FW_FailODError
  64. //----------------------------------------------------------------------------------------
  65.  
  66. void FW_FailOnEvError(Environment* ev)
  67. {
  68.     FW_PlatformError theError = FW_GetEvError(ev);
  69.     if (theError != FW_xNoError)
  70.     {
  71.         FW_SetEvError(ev, FW_xNoError);
  72.         FW_THROW(FW_XException(theError));
  73.     }    
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // FW_SetException
  78. //----------------------------------------------------------------------------------------
  79.  
  80. void FW_SetException(Environment *ev, const FW_XException& exception)
  81. {
  82.     FW_SetEvError(ev, exception.GetPlatformError());
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. // FW_SetEvError
  87. //----------------------------------------------------------------------------------------
  88.  
  89. void FW_SetEvError(Environment* ev, FW_PlatformError error)
  90. {
  91.     if (error)
  92.     {
  93.         ODException *x = (ODException*) SOMMalloc(sizeof(ODException));
  94.         x->error = error;
  95.         x->message[0] = '\0';
  96.         somSetException(ev, USER_EXCEPTION, ex_ODException, x);
  97.     }
  98.     else if (ev->_major != NO_EXCEPTION)
  99.     {
  100.         somExceptionFree(ev);
  101.         ev->_major = NO_EXCEPTION;
  102.     }
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // FW_GetEvError
  107. //----------------------------------------------------------------------------------------
  108.  
  109. FW_PlatformError FW_GetEvError(Environment* ev)
  110. {
  111.     if (ev->_major)
  112.     {
  113.         const char *excpName = somExceptionId(ev);
  114.         if (FW_PrimitiveStringEqual(excpName, ex_ODException) == 1)
  115.         {
  116.             ODException *x = (ODException*) somExceptionValue(ev);
  117.             return x->error;
  118.         }
  119.         else
  120.         {
  121.             // Don't know what to do, its a non-OpenDoc error
  122.             FW_DEBUG_MESSAGE("Environment has non-OpenDoc error");
  123.             return FW_xUnknownError;
  124.         }
  125.     }
  126.     else
  127.         return FW_xNoError;
  128. }
  129.  
  130. //========================================================================================
  131. // CLASS FW_XException
  132. //========================================================================================
  133.  
  134. FW_DEFINE_CLASS_M0(FW_XException)
  135. FW_DEFINE_EXCEPTION(FW_XException)
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_XException::FW_XException
  139. //----------------------------------------------------------------------------------------
  140.  
  141. FW_XException::FW_XException(const FW_XException& exception) :
  142.     fPlatformError(exception.fPlatformError)
  143. {
  144.     FW_ASSERT(fPlatformError != 0);
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    FW_XException::FW_XException
  149. //----------------------------------------------------------------------------------------
  150.  
  151. FW_XException::FW_XException(FW_PlatformError theError) :
  152.     fPlatformError(theError == 0 ? FW_xUnknownError : theError)
  153. {
  154.     FW_ASSERT(fPlatformError != 0);
  155. }
  156.  
  157. //----------------------------------------------------------------------------------------
  158. //    FW_XException::GetPlatformError
  159. //----------------------------------------------------------------------------------------
  160.  
  161. FW_PlatformError FW_XException::GetPlatformError(void) const
  162. {
  163.     return fPlatformError;
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_XException::~FW_XException
  168. //----------------------------------------------------------------------------------------
  169.  
  170. FW_XException::~FW_XException()
  171. {
  172. }
  173.  
  174. //========================================================================================
  175. // CLASS FW_CPrivInstallNewHandler
  176. //========================================================================================
  177.  
  178. static void FW_PrivNewHandler(void)
  179. {
  180.     FW_FailOnError(kODErrOutOfMemory);
  181. }
  182.  
  183. class FW_CPrivInstallNewHandler
  184. {
  185. public:
  186.     FW_CPrivInstallNewHandler() { ::set_new_handler(FW_PrivNewHandler); }
  187.     ~FW_CPrivInstallNewHandler() {}
  188. };
  189.  
  190. FW_CPrivInstallNewHandler gInstallNewHandler;
  191.