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.

155 lines
5.9 KiB

  1. // OsExc.cpp -- Operating System Exception template class definition
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include "scuOsExc.h"
  8. using namespace scu;
  9. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  10. /////////////////////////// PUBLIC /////////////////////////////////
  11. // Types
  12. // C'tors/D'tors
  13. // Operators
  14. // Operations
  15. // Access
  16. // Predicates
  17. // Static Variables
  18. /////////////////////////// PROTECTED /////////////////////////////////
  19. // C'tors/D'tors
  20. // Operators
  21. // Operations
  22. // Access
  23. // Predicates
  24. // Static Variables
  25. /////////////////////////// PRIVATE /////////////////////////////////
  26. // C'tors/D'tors
  27. // Operators
  28. // Operations
  29. // Access
  30. // Predicates
  31. // Static Variables
  32. /////////////////////////// PUBLIC /////////////////////////////////
  33. // Types
  34. // C'tors/D'tors
  35. OsException::OsException(CauseCode cc) throw()
  36. : ExcTemplate<Exception::fcOS, DWORD>(cc),
  37. m_lpDescription(0)
  38. {}
  39. OsException::OsException(HRESULT hr) throw()
  40. : ExcTemplate<Exception::fcOS, DWORD>(static_cast<DWORD>(hr)),
  41. m_lpDescription(0)
  42. {}
  43. OsException::OsException(OsException const &rhs)
  44. : ExcTemplate<Exception::fcOS, DWORD>(rhs),
  45. m_lpDescription(0) // force the copy to cache it's own description.
  46. {}
  47. OsException::~OsException() throw()
  48. {
  49. try
  50. {
  51. if (m_lpDescription)
  52. LocalFree(m_lpDescription);
  53. }
  54. catch (...)
  55. {
  56. }
  57. }
  58. // Operators
  59. // Operations
  60. Exception *
  61. OsException::Clone() const
  62. {
  63. return new OsException(*this);
  64. }
  65. void
  66. OsException::Raise() const
  67. {
  68. throw *this;
  69. }
  70. // Access
  71. char const *
  72. OsException::Description() const
  73. {
  74. if (!m_lpDescription)
  75. {
  76. // cache the description
  77. DWORD const dwBaseFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER |
  78. FORMAT_MESSAGE_IGNORE_INSERTS;
  79. CauseCode const cc = Cause();
  80. DWORD const dwLanguageId = LANG_NEUTRAL;
  81. DWORD cMsgLength;
  82. // Note: The compiler complains without the
  83. // reinterpret_cast<LPTSTR> even though the declarations appear
  84. // compatible. Something strange in the declaration of LPTSTR and
  85. // LPSTR used by FormatMessageA.
  86. cMsgLength = FormatMessage(dwBaseFlags | FORMAT_MESSAGE_FROM_SYSTEM,
  87. NULL, cc, dwLanguageId,
  88. reinterpret_cast<LPTSTR>(&m_lpDescription),
  89. 0, NULL);
  90. if (0 == cMsgLength)
  91. {
  92. cMsgLength = FormatMessage(dwBaseFlags |
  93. FORMAT_MESSAGE_FROM_HMODULE,
  94. GetModuleHandle(NULL), cc,
  95. dwLanguageId,
  96. reinterpret_cast<LPTSTR>(&m_lpDescription),
  97. 0, NULL);
  98. if (0 == cMsgLength)
  99. {
  100. // if this fails, assume a message doesn't exist
  101. cMsgLength = FormatMessage(dwBaseFlags |
  102. FORMAT_MESSAGE_FROM_HMODULE,
  103. GetModuleHandle(TEXT("winscard")),
  104. cc, dwLanguageId,
  105. reinterpret_cast<LPTSTR>(&m_lpDescription),
  106. 0, NULL);
  107. }
  108. }
  109. }
  110. return m_lpDescription;
  111. }
  112. // Predicates
  113. // Static Variables
  114. /////////////////////////// PROTECTED /////////////////////////////////
  115. // C'tors/D'tors
  116. // Operators
  117. // Operations
  118. // Access
  119. // Predicates
  120. // Static Variables
  121. /////////////////////////// PRIVATE /////////////////////////////////
  122. // C'tors/D'tors
  123. // Operators
  124. // Operations
  125. // Access
  126. // Predicates
  127. // Static Variables