Source code of Windows XP (NT5)
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.

138 lines
3.7 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CException.h
  7. //
  8. // Description:
  9. // This file contains the declarations of base class for all exception
  10. // classes.
  11. //
  12. // Implementation File:
  13. // None.
  14. //
  15. // Maintained By:
  16. // Vij Vasu (Vvasu) 26-APR-2000
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. // Make sure that this file is included only once per compile path.
  20. #pragma once
  21. //////////////////////////////////////////////////////////////////////////////
  22. // Include Files
  23. //////////////////////////////////////////////////////////////////////////////
  24. // For HRESULT, WCHAR, etc.
  25. #include <windef.h>
  26. //////////////////////////////////////////////////////////////////////
  27. // Macro Definitions
  28. //////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Shorthand for throwing different exceptions.
  31. //
  32. #define THROW_EXCEPTION( _hrErrorCode ) \
  33. throw CException( _hrErrorCode, TEXT( __FILE__ ), __LINE__ )
  34. //////////////////////////////////////////////////////////////////////////////
  35. //++
  36. //
  37. // class CException
  38. //
  39. // Description:
  40. // The CException is the base class for all exceptions thrown by
  41. // functions defined in this library.
  42. //
  43. // An object of this class must have the m_hrErrorCode, m_pszFile and
  44. // m_uiLineNumber members initialized.
  45. //
  46. //--
  47. //////////////////////////////////////////////////////////////////////////////
  48. class CException
  49. {
  50. public:
  51. //////////////////////////////////////////////////////////////////////////
  52. // Public constructors and destructors
  53. //////////////////////////////////////////////////////////////////////////
  54. // Constructor.
  55. CException(
  56. HRESULT hrErrorCodeIn
  57. , const WCHAR * pszFileNameIn
  58. , UINT uiLineNumberIn
  59. ) throw()
  60. : m_hrErrorCode( hrErrorCodeIn )
  61. , m_pszFileName( pszFileNameIn )
  62. , m_uiLineNumber( uiLineNumberIn )
  63. {
  64. }
  65. // Copy constructor.
  66. CException( const CException & ceSrcIn ) throw()
  67. : m_hrErrorCode( ceSrcIn.m_hrErrorCode )
  68. , m_pszFileName( ceSrcIn.m_pszFileName )
  69. , m_uiLineNumber( ceSrcIn.m_uiLineNumber )
  70. {
  71. }
  72. // Default virtual destructor.
  73. virtual
  74. ~CException() throw() {}
  75. //////////////////////////////////////////////////////////////////////////
  76. // Public Methods
  77. //////////////////////////////////////////////////////////////////////////
  78. // Assignment operator.
  79. const CException &
  80. operator =( const CException & ceSrcIn ) throw()
  81. {
  82. m_hrErrorCode = ceSrcIn.m_hrErrorCode;
  83. m_pszFileName = ceSrcIn.m_pszFileName;
  84. m_uiLineNumber = ceSrcIn.m_uiLineNumber;
  85. return *this;
  86. }
  87. //
  88. // Accessor methods.
  89. //
  90. HRESULT
  91. HrGetErrorCode() const throw() { return m_hrErrorCode; }
  92. void
  93. SetErrorCode( HRESULT hrNewCode ) throw() { m_hrErrorCode = hrNewCode; }
  94. const WCHAR *
  95. PszGetThrowingFile() const throw() { return m_pszFileName; }
  96. UINT
  97. UiGetThrowingLine() const throw() { return m_uiLineNumber; }
  98. private:
  99. //////////////////////////////////////////////////////////////////////////
  100. // Private members
  101. //////////////////////////////////////////////////////////////////////////
  102. // Default construction is not allowed.
  103. CException();
  104. //////////////////////////////////////////////////////////////////////////
  105. // Private data
  106. //////////////////////////////////////////////////////////////////////////
  107. HRESULT m_hrErrorCode;
  108. const WCHAR * m_pszFileName;
  109. UINT m_uiLineNumber;
  110. }; //*** class CException