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.

432 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Exceptions.h
  7. //
  8. // Description:
  9. // This file contains the declarations of many exception classes.
  10. //
  11. // Implementation File:
  12. // None.
  13. //
  14. // Maintained By:
  15. // Vij Vasu (Vvasu) 03-MAR-2000
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. // Make sure that this file is included only once per compile path.
  19. #pragma once
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Include Files
  22. //////////////////////////////////////////////////////////////////////////////
  23. // For HRESULT, WCHAR, etc.
  24. #include <windef.h>
  25. // For the base class of all exceptions
  26. #include "CException.h"
  27. // For the CStr class
  28. #include "CStr.h"
  29. //////////////////////////////////////////////////////////////////////
  30. // Macro Definitions
  31. //////////////////////////////////////////////////////////////////////////////
  32. //
  33. // Shorthand for throwing different exceptions.
  34. //
  35. #define THROW_ASSERT( _hrErrorCode, _pszMessage ) \
  36. throw CAssert( _hrErrorCode, TEXT( __FILE__ ), __LINE__, TEXT( _pszMessage ) )
  37. #define THROW_RUNTIME_ERROR( _hrErrorCode, _stringId ) \
  38. throw CRuntimeError( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  39. #define THROW_CONFIG_ERROR( _hrErrorCode, _stringId ) \
  40. throw CConfigError( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  41. #define THROW_ABORT( _hrErrorCode, _stringId ) \
  42. throw CAbortException( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  43. //////////////////////////////////////////////////////////////////////
  44. // External variable declarations
  45. //////////////////////////////////////////////////////////////////////////////
  46. // Handle to the instance of this DLL
  47. extern HINSTANCE g_hInstance;
  48. //////////////////////////////////////////////////////////////////////////////
  49. //++
  50. //
  51. // class CExceptionWithString
  52. //
  53. // Description:
  54. // The class is a CException with an additional message string.
  55. //
  56. //--
  57. //////////////////////////////////////////////////////////////////////////////
  58. class CExceptionWithString : public CException
  59. {
  60. public:
  61. //////////////////////////////////////////////////////////////////////////
  62. // Public type definitions
  63. //////////////////////////////////////////////////////////////////////////
  64. typedef CException BaseClass;
  65. //////////////////////////////////////////////////////////////////////////
  66. // Public constructors and destructors
  67. //////////////////////////////////////////////////////////////////////////
  68. // Constructor ( string id overload )
  69. CExceptionWithString(
  70. HRESULT hrErrorCodeIn
  71. , const WCHAR * pcszFileNameIn
  72. , UINT uiLineNumberIn
  73. , UINT uiErrorStringIdIn
  74. ) throw()
  75. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  76. , m_fHasUserBeenNotified( false )
  77. {
  78. AssignString( uiErrorStringIdIn );
  79. }
  80. // Constructor ( character string overload )
  81. CExceptionWithString(
  82. HRESULT hrErrorCodeIn
  83. , const WCHAR * pcszFileNameIn
  84. , UINT uiLineNumberIn
  85. , const WCHAR * pcszErrorStringIn
  86. ) throw()
  87. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  88. , m_fHasUserBeenNotified( false )
  89. {
  90. AssignString( pcszErrorStringIn );
  91. }
  92. // Copy constructor.
  93. CExceptionWithString( const CExceptionWithString & cesuSrcIn ) throw()
  94. : BaseClass( cesuSrcIn )
  95. , m_fHasUserBeenNotified( cesuSrcIn.m_fHasUserBeenNotified )
  96. {
  97. AssignString( cesuSrcIn.m_strErrorString );
  98. }
  99. // Default destructor.
  100. ~CExceptionWithString() throw() {}
  101. //////////////////////////////////////////////////////////////////////////
  102. // Public methods
  103. //////////////////////////////////////////////////////////////////////////
  104. // Assignment operator.
  105. const CExceptionWithString &
  106. operator =( const CExceptionWithString & cesuSrcIn ) throw()
  107. {
  108. *( static_cast< BaseClass * >( this ) ) = cesuSrcIn;
  109. AssignString( cesuSrcIn.m_strErrorString );
  110. m_fHasUserBeenNotified = cesuSrcIn.m_fHasUserBeenNotified;
  111. return *this;
  112. }
  113. //
  114. // Accessor methods.
  115. //
  116. const CStr &
  117. StrGetErrorString() const throw() { return m_strErrorString; }
  118. void
  119. SetErrorString( const WCHAR * pcszSrcIn ) throw()
  120. {
  121. AssignString( pcszSrcIn );
  122. }
  123. bool
  124. FHasUserBeenNotified() const throw() { return m_fHasUserBeenNotified; }
  125. void
  126. SetUserNotified( bool fNotifiedIn = true ) throw() { m_fHasUserBeenNotified = fNotifiedIn; }
  127. private:
  128. //////////////////////////////////////////////////////////////////////////
  129. // Private member functions
  130. //////////////////////////////////////////////////////////////////////////
  131. // Function to set the member string ( string id overload ).
  132. void AssignString( UINT uiStringIdIn ) throw()
  133. {
  134. try
  135. {
  136. m_strErrorString.Empty();
  137. m_strErrorString.LoadString( g_hInstance, uiStringIdIn );
  138. }
  139. catch( ... )
  140. {
  141. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  142. THR( E_UNEXPECTED );
  143. } // catch all: cannot let an exception propagate out of any of the methods of this class
  144. }
  145. // Function to set the member string ( character string overload ).
  146. void AssignString( const WCHAR * pcszSrcIn ) throw()
  147. {
  148. try
  149. {
  150. m_strErrorString.Empty();
  151. m_strErrorString.Assign( pcszSrcIn );
  152. }
  153. catch( ... )
  154. {
  155. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  156. THR( E_UNEXPECTED );
  157. } // catch all: cannot let an exception propagate out of any of the methods of this class
  158. }
  159. // Function to set the member string ( CStr overload ).
  160. void AssignString( const CStr & rcstrSrcIn ) throw()
  161. {
  162. try
  163. {
  164. m_strErrorString.Empty();
  165. m_strErrorString.Assign( rcstrSrcIn );
  166. }
  167. catch( ... )
  168. {
  169. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  170. THR( E_UNEXPECTED );
  171. } // catch all: cannot let an exception propagate out of any of the methods of this class
  172. }
  173. //////////////////////////////////////////////////////////////////////////
  174. // Private data
  175. //////////////////////////////////////////////////////////////////////////
  176. CStr m_strErrorString;
  177. // Indicates if the user has been notified about this exception or not.
  178. bool m_fHasUserBeenNotified;
  179. }; //*** class CExceptionWithString
  180. //////////////////////////////////////////////////////////////////////////////
  181. //++
  182. //
  183. // class CAssert
  184. //
  185. // Description:
  186. // This class of exceptions is used to represent programming errors or
  187. // invalid assumptions.
  188. //
  189. // The accompanying message is not expected to be localized.
  190. //
  191. //--
  192. //////////////////////////////////////////////////////////////////////////////
  193. class CAssert : public CExceptionWithString
  194. {
  195. public:
  196. //////////////////////////////////////////////////////////////////////////
  197. // Public type definitions
  198. //////////////////////////////////////////////////////////////////////////
  199. typedef CExceptionWithString BaseClass;
  200. //////////////////////////////////////////////////////////////////////////
  201. // Public constructors and destructors
  202. //////////////////////////////////////////////////////////////////////////
  203. // CAssert ( string id overload ).
  204. CAssert(
  205. HRESULT hrErrorCodeIn
  206. , const WCHAR * pcszFileNameIn
  207. , UINT uiLineNumberIn
  208. , UINT uiErrorStringIdIn
  209. ) throw()
  210. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  211. {
  212. }
  213. // Constructor ( character string overload )
  214. CAssert(
  215. HRESULT hrErrorCodeIn
  216. , const WCHAR * pcszFileNameIn
  217. , UINT uiLineNumberIn
  218. , const WCHAR * pcszErrorStringIn
  219. ) throw()
  220. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  221. {
  222. }
  223. }; //*** class CAssert
  224. //////////////////////////////////////////////////////////////////////////////
  225. //++
  226. //
  227. // class CRuntimeError
  228. //
  229. // Description:
  230. // This class of exceptions is used to signal runtime errors such as memory
  231. // exhaustion, failure of Win32 API calls, etc.
  232. //
  233. // The accompanying message may be shown to the user and should therefore
  234. // be localized.
  235. //
  236. //--
  237. //////////////////////////////////////////////////////////////////////////////
  238. class CRuntimeError : public CExceptionWithString
  239. {
  240. public:
  241. //////////////////////////////////////////////////////////////////////////
  242. // Public type definitions
  243. //////////////////////////////////////////////////////////////////////////
  244. typedef CExceptionWithString BaseClass;
  245. //////////////////////////////////////////////////////////////////////////
  246. // Public constructors and destructors
  247. //////////////////////////////////////////////////////////////////////////
  248. // Constructor ( string id overload ).
  249. CRuntimeError(
  250. HRESULT hrErrorCodeIn
  251. , const WCHAR * pcszFileNameIn
  252. , UINT uiLineNumberIn
  253. , UINT uiErrorStringIdIn
  254. ) throw()
  255. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  256. {
  257. }
  258. // Constructor ( character string overload )
  259. CRuntimeError(
  260. HRESULT hrErrorCodeIn
  261. , const WCHAR * pcszFileNameIn
  262. , UINT uiLineNumberIn
  263. , const WCHAR * pcszErrorStringIn
  264. ) throw()
  265. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  266. {
  267. }
  268. }; //*** class CRuntimeError
  269. //////////////////////////////////////////////////////////////////////////////
  270. //++
  271. //
  272. // class CAbortException
  273. //
  274. // Description:
  275. // This exception is thrown to indicate that the configuration operation
  276. // was aborted.
  277. //
  278. // The accompanying message may be shown to the user and should therefore
  279. // be localized.
  280. //
  281. //--
  282. //////////////////////////////////////////////////////////////////////////////
  283. class CAbortException : public CExceptionWithString
  284. {
  285. public:
  286. //////////////////////////////////////////////////////////////////////////
  287. // Public type definitions
  288. //////////////////////////////////////////////////////////////////////////
  289. typedef CExceptionWithString BaseClass;
  290. //////////////////////////////////////////////////////////////////////////
  291. // Public constructors and destructors
  292. //////////////////////////////////////////////////////////////////////////
  293. // Constructor ( string id overload ).
  294. CAbortException(
  295. HRESULT hrErrorCodeIn
  296. , const WCHAR * pcszFileNameIn
  297. , UINT uiLineNumberIn
  298. , UINT uiErrorStringIdIn
  299. ) throw()
  300. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  301. {
  302. }
  303. // Constructor ( character string overload )
  304. CAbortException(
  305. HRESULT hrErrorCodeIn
  306. , const WCHAR * pcszFileNameIn
  307. , UINT uiLineNumberIn
  308. , const WCHAR * pcszErrorStringIn
  309. ) throw()
  310. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  311. {
  312. }
  313. }; //*** class CAbortException
  314. //////////////////////////////////////////////////////////////////////////////
  315. //++
  316. //
  317. // class CConfigError
  318. //
  319. // Description:
  320. // This class of exceptions is used to signal errors related to cluster
  321. // configuration. For example, an object of this class is thrown if the
  322. // OS version of the computer cannot support the requested configuration
  323. // step.
  324. //
  325. // The accompanying message may be shown to the user and should therefore
  326. // be localized.
  327. //
  328. //--
  329. //////////////////////////////////////////////////////////////////////////////
  330. class CConfigError : public CExceptionWithString
  331. {
  332. public:
  333. //////////////////////////////////////////////////////////////////////////
  334. // Public type definitions
  335. //////////////////////////////////////////////////////////////////////////
  336. typedef CExceptionWithString BaseClass;
  337. //////////////////////////////////////////////////////////////////////////
  338. // Public constructors and destructors
  339. //////////////////////////////////////////////////////////////////////////
  340. // Constructor ( string id overload )
  341. CConfigError(
  342. HRESULT hrErrorCodeIn
  343. , const WCHAR * pcszFileNameIn
  344. , UINT uiLineNumberIn
  345. , UINT uiErrorStringIdIn
  346. ) throw()
  347. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  348. {
  349. }
  350. // Constructor ( character string overload )
  351. CConfigError(
  352. HRESULT hrErrorCodeIn
  353. , const WCHAR * pcszFileNameIn
  354. , UINT uiLineNumberIn
  355. , const WCHAR * pcszErrorStringIn
  356. ) throw()
  357. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  358. {
  359. }
  360. }; //*** class CConfigError