Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. vs_seh.hxx
  5. Abstract:
  6. Exception handling support code
  7. Former name: bsexcept.hxx
  8. Author:
  9. Stefan R. Steiner [SSteiner] 15-Apr-1998
  10. Revision History:
  11. ssteiner 09/10/98 - Removed the exception classes. Now only throwing
  12. HRESULTs.
  13. aoltean 02/02/2000 - Moved into VSS under a new name.
  14. --*/
  15. #ifndef _H_VSS_SEH
  16. #define _H_VSS_SEH
  17. #include <eh.h>
  18. ////////////////////////////////////////////////////////////////////////
  19. // Standard foo for file name aliasing. This code block must be after
  20. // all includes of VSS header files.
  21. //
  22. #ifdef VSS_FILE_ALIAS
  23. #undef VSS_FILE_ALIAS
  24. #endif
  25. #define VSS_FILE_ALIAS "INCSEHH"
  26. //
  27. ////////////////////////////////////////////////////////////////////////
  28. /*++
  29. Routine Description:
  30. The Structured Exception Handling translator function. Translates
  31. SEH exceptions to C++ Native exceptions. Generates a trace message.
  32. Arguments:
  33. ExceptionCode - SEH exception code.
  34. pEP - pointer to a more detailed explanation of why the exception
  35. was thrown.
  36. Return Value:
  37. None
  38. Throws:
  39. HRESULT - translated exception code from windows exception code to HRESULT.
  40. --*/
  41. void _cdecl BsSETranslator(
  42. IN DWORD dwExceptionCode,
  43. IN struct _EXCEPTION_POINTERS *pEP
  44. );
  45. /*++
  46. Macro Description:
  47. This macro installs the SEH translation function. Assumes that
  48. BS_UNINSTALL_SEH_HANDLER will be
  49. Arguments:
  50. IN hr - HRESULT code to throw.
  51. Return Value:
  52. None.
  53. --*/
  54. class BsSeHandler {
  55. public:
  56. BsSeHandler( _se_translator_function seFunc = SeHandler ) {
  57. m_pOldSeHandlerFunc = _set_se_translator( seFunc );
  58. }
  59. ~BsSeHandler() {
  60. _set_se_translator( m_pOldSeHandlerFunc );
  61. }
  62. static void _cdecl SeHandler(
  63. IN unsigned int uiExceptionCode,
  64. IN struct _EXCEPTION_POINTERS *pEP
  65. );
  66. private:
  67. _se_translator_function m_pOldSeHandlerFunc;
  68. };
  69. #define BS_STANDARD_CATCH() \
  70. catch( HRESULT CaughtHr ) { \
  71. hr = CaughtHr; \
  72. BsDebugTraceAlways( 0, DEBUG_TRACE_CATCH_EXCEPTIONS, \
  73. ( L"HRESULT EXCEPTION CAUGHT: hr: 0x%x", hr ) ); \
  74. } \
  75. catch( ... ) { \
  76. hr = E_UNEXPECTED; \
  77. BsDebugTraceAlways( 0, DEBUG_TRACE_CATCH_EXCEPTIONS, \
  78. ( L"UNKNOWN EXCEPTION CAUGHT, returning: hr: 0x%x", hr ) ); \
  79. }
  80. /*++
  81. Macro Description:
  82. This macro is used to throw a C++ exception. Before it does
  83. so, it prints out a trace statement.
  84. Arguments:
  85. IN hr - HRESULT code to throw.
  86. Return Value:
  87. None.
  88. --*/
  89. #define BS_THROW( hr ) { \
  90. BsDebugTraceAlways( 0, DEBUG_TRACE_CATCH_EXCEPTIONS, \
  91. ( L"BS_THROW: Throwing HRESULT code 0x%08x", hr ) ) \
  92. throw( ( HRESULT ) hr ); \
  93. }
  94. #endif