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.

564 lines
18 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2002 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. // Ozan Ozhan (OzanO) 19-JAN-2002
  16. // Vij Vasu (Vvasu) 03-MAR-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. // For the base class of all exceptions
  27. #include "CException.h"
  28. // For the CStr class
  29. #include "CStr.h"
  30. //////////////////////////////////////////////////////////////////////
  31. // Macro Definitions
  32. //////////////////////////////////////////////////////////////////////////////
  33. //
  34. // Shorthand for throwing different exceptions.
  35. //
  36. #define THROW_ASSERT( _hrErrorCode, _pszMessage ) \
  37. throw CAssert( _hrErrorCode, TEXT( __FILE__ ), __LINE__, TEXT( _pszMessage ) )
  38. #define THROW_RUNTIME_ERROR( _hrErrorCode, _stringId ) \
  39. throw CRuntimeError( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  40. #define THROW_RUNTIME_ERROR_REF( _hrErrorCode, _stringId, _stringRefId ) \
  41. throw CRuntimeError( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId, _stringRefId )
  42. #define THROW_CONFIG_ERROR( _hrErrorCode, _stringId ) \
  43. throw CConfigError( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  44. #define THROW_ABORT( _hrErrorCode, _stringId ) \
  45. throw CAbortException( _hrErrorCode, TEXT( __FILE__ ), __LINE__, _stringId )
  46. //////////////////////////////////////////////////////////////////////
  47. // External variable declarations
  48. //////////////////////////////////////////////////////////////////////////////
  49. // Handle to the instance of this DLL
  50. extern HINSTANCE g_hInstance;
  51. //////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // class CExceptionWithString
  55. //
  56. // Description:
  57. // The class is a CException with an additional message string.
  58. //
  59. //--
  60. //////////////////////////////////////////////////////////////////////////////
  61. class CExceptionWithString : public CException
  62. {
  63. public:
  64. //////////////////////////////////////////////////////////////////////////
  65. // Public type definitions
  66. //////////////////////////////////////////////////////////////////////////
  67. typedef CException BaseClass;
  68. //////////////////////////////////////////////////////////////////////////
  69. // Public constructors and destructors
  70. //////////////////////////////////////////////////////////////////////////
  71. // Constructor ( string id overload )
  72. CExceptionWithString(
  73. HRESULT hrErrorCodeIn
  74. , const WCHAR * pcszFileNameIn
  75. , UINT uiLineNumberIn
  76. , UINT uiErrorStringIdIn
  77. ) throw()
  78. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  79. , m_fHasUserBeenNotified( false )
  80. {
  81. AssignString( uiErrorStringIdIn );
  82. m_strErrorRefString = NULL;
  83. }
  84. // Constructor ( character string overload )
  85. CExceptionWithString(
  86. HRESULT hrErrorCodeIn
  87. , const WCHAR * pcszFileNameIn
  88. , UINT uiLineNumberIn
  89. , const WCHAR * pcszErrorStringIn
  90. ) throw()
  91. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  92. , m_fHasUserBeenNotified( false )
  93. {
  94. AssignString( pcszErrorStringIn );
  95. m_strErrorRefString = NULL;
  96. }
  97. // Constructor ( string id & ref string id overload )
  98. CExceptionWithString(
  99. HRESULT hrErrorCodeIn
  100. , const WCHAR * pcszFileNameIn
  101. , UINT uiLineNumberIn
  102. , UINT uiErrorStringIdIn
  103. , UINT uiErrorRefStringIdIn
  104. ) throw()
  105. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  106. , m_fHasUserBeenNotified( false )
  107. {
  108. AssignString( uiErrorStringIdIn );
  109. AssignRefString( uiErrorRefStringIdIn );
  110. }
  111. // Constructor ( character string & ref character string overload )
  112. CExceptionWithString(
  113. HRESULT hrErrorCodeIn
  114. , const WCHAR * pcszFileNameIn
  115. , UINT uiLineNumberIn
  116. , const WCHAR * pcszErrorStringIn
  117. , const WCHAR * pcszErrorRefStringIn
  118. ) throw()
  119. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn )
  120. , m_fHasUserBeenNotified( false )
  121. {
  122. AssignString( pcszErrorStringIn );
  123. AssignRefString( pcszErrorRefStringIn );
  124. }
  125. // Copy constructor.
  126. CExceptionWithString( const CExceptionWithString & cesuSrcIn ) throw()
  127. : BaseClass( cesuSrcIn )
  128. , m_fHasUserBeenNotified( cesuSrcIn.m_fHasUserBeenNotified )
  129. {
  130. AssignString( cesuSrcIn.m_strErrorString );
  131. AssignRefString( cesuSrcIn.m_strErrorRefString );
  132. }
  133. // Default destructor.
  134. ~CExceptionWithString() throw() {}
  135. //////////////////////////////////////////////////////////////////////////
  136. // Public methods
  137. //////////////////////////////////////////////////////////////////////////
  138. // Assignment operator.
  139. const CExceptionWithString &
  140. operator =( const CExceptionWithString & cesuSrcIn ) throw()
  141. {
  142. *( static_cast< BaseClass * >( this ) ) = cesuSrcIn;
  143. AssignString( cesuSrcIn.m_strErrorString );
  144. AssignRefString( cesuSrcIn.m_strErrorRefString );
  145. m_fHasUserBeenNotified = cesuSrcIn.m_fHasUserBeenNotified;
  146. return *this;
  147. }
  148. //
  149. // Accessor methods.
  150. //
  151. const CStr &
  152. StrGetErrorString() const throw() { return m_strErrorString; }
  153. void
  154. SetErrorString( UINT uiErrorStringIdIn ) throw()
  155. {
  156. AssignString( uiErrorStringIdIn );
  157. }
  158. void
  159. SetErrorString( const WCHAR * pcszSrcIn ) throw()
  160. {
  161. AssignString( pcszSrcIn );
  162. }
  163. const CStr &
  164. StrGetErrorRefString() const throw() { return m_strErrorRefString; }
  165. void
  166. SetErrorRefString( UINT uiErrorRefStringIdIn ) throw()
  167. {
  168. AssignRefString( uiErrorRefStringIdIn );
  169. }
  170. void
  171. SetErrorRefString( const WCHAR * pcszSrcIn ) throw()
  172. {
  173. AssignRefString( pcszSrcIn );
  174. }
  175. bool
  176. FHasUserBeenNotified() const throw() { return m_fHasUserBeenNotified; }
  177. void
  178. SetUserNotified( bool fNotifiedIn = true ) throw() { m_fHasUserBeenNotified = fNotifiedIn; }
  179. private:
  180. //////////////////////////////////////////////////////////////////////////
  181. // Private member functions
  182. //////////////////////////////////////////////////////////////////////////
  183. // Function to set the member string ( string id overload ).
  184. void AssignString( UINT uiStringIdIn ) throw()
  185. {
  186. try
  187. {
  188. m_strErrorString.Empty();
  189. m_strErrorString.LoadString( g_hInstance, uiStringIdIn );
  190. }
  191. catch( ... )
  192. {
  193. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  194. THR( E_UNEXPECTED );
  195. } // catch all: cannot let an exception propagate out of any of the methods of this class
  196. }
  197. // Function to set the member string ( character string overload ).
  198. void AssignString( const WCHAR * pcszSrcIn ) throw()
  199. {
  200. try
  201. {
  202. m_strErrorString.Empty();
  203. m_strErrorString.Assign( pcszSrcIn );
  204. }
  205. catch( ... )
  206. {
  207. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  208. THR( E_UNEXPECTED );
  209. } // catch all: cannot let an exception propagate out of any of the methods of this class
  210. }
  211. // Function to set the member string ( CStr overload ).
  212. void AssignString( const CStr & rcstrSrcIn ) throw()
  213. {
  214. try
  215. {
  216. m_strErrorString.Empty();
  217. m_strErrorString.Assign( rcstrSrcIn );
  218. }
  219. catch( ... )
  220. {
  221. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  222. THR( E_UNEXPECTED );
  223. } // catch all: cannot let an exception propagate out of any of the methods of this class
  224. }
  225. // Function to set the member REF string ( REF string id overload ).
  226. void AssignRefString( UINT uiRefStringIdIn ) throw()
  227. {
  228. try
  229. {
  230. m_strErrorRefString.Empty();
  231. m_strErrorRefString.LoadString( g_hInstance, uiRefStringIdIn );
  232. }
  233. catch( ... )
  234. {
  235. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  236. THR( E_UNEXPECTED );
  237. } // catch all: cannot let an exception propagate out of any of the methods of this class
  238. }
  239. // Function to set the member REF string ( REF character string overload ).
  240. void AssignRefString( const WCHAR * pcszRefSrcIn ) throw()
  241. {
  242. try
  243. {
  244. m_strErrorRefString.Empty();
  245. m_strErrorRefString.Assign( pcszRefSrcIn );
  246. }
  247. catch( ... )
  248. {
  249. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  250. THR( E_UNEXPECTED );
  251. } // catch all: cannot let an exception propagate out of any of the methods of this class
  252. }
  253. // Function to set the member REF string ( CStr overload ).
  254. void AssignRefString( const CStr & rcstrRefSrcIn ) throw()
  255. {
  256. try
  257. {
  258. m_strErrorRefString.Empty();
  259. m_strErrorRefString.Assign( rcstrRefSrcIn );
  260. }
  261. catch( ... )
  262. {
  263. // If an error has occurred, nothing can be done - we are most probably in a stack unwind anyway.
  264. THR( E_UNEXPECTED );
  265. } // catch all: cannot let an exception propagate out of any of the methods of this class
  266. }
  267. //////////////////////////////////////////////////////////////////////////
  268. // Private data
  269. //////////////////////////////////////////////////////////////////////////
  270. // Error message string
  271. CStr m_strErrorString;
  272. // Error reference message string
  273. CStr m_strErrorRefString;
  274. // Indicates if the user has been notified about this exception or not.
  275. bool m_fHasUserBeenNotified;
  276. }; //*** class CExceptionWithString
  277. //////////////////////////////////////////////////////////////////////////////
  278. //++
  279. //
  280. // class CAssert
  281. //
  282. // Description:
  283. // This class of exceptions is used to represent programming errors or
  284. // invalid assumptions.
  285. //
  286. // The accompanying message is not expected to be localized.
  287. //
  288. //--
  289. //////////////////////////////////////////////////////////////////////////////
  290. class CAssert : public CExceptionWithString
  291. {
  292. public:
  293. //////////////////////////////////////////////////////////////////////////
  294. // Public type definitions
  295. //////////////////////////////////////////////////////////////////////////
  296. typedef CExceptionWithString BaseClass;
  297. //////////////////////////////////////////////////////////////////////////
  298. // Public constructors and destructors
  299. //////////////////////////////////////////////////////////////////////////
  300. // CAssert ( string id overload ).
  301. CAssert(
  302. HRESULT hrErrorCodeIn
  303. , const WCHAR * pcszFileNameIn
  304. , UINT uiLineNumberIn
  305. , UINT uiErrorStringIdIn
  306. ) throw()
  307. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  308. {
  309. }
  310. // Constructor ( character string overload )
  311. CAssert(
  312. HRESULT hrErrorCodeIn
  313. , const WCHAR * pcszFileNameIn
  314. , UINT uiLineNumberIn
  315. , const WCHAR * pcszErrorStringIn
  316. ) throw()
  317. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  318. {
  319. }
  320. }; //*** class CAssert
  321. //////////////////////////////////////////////////////////////////////////////
  322. //++
  323. //
  324. // class CRuntimeError
  325. //
  326. // Description:
  327. // This class of exceptions is used to signal runtime errors such as memory
  328. // exhaustion, failure of Win32 API calls, etc.
  329. //
  330. // The accompanying message may be shown to the user and should therefore
  331. // be localized.
  332. //
  333. //--
  334. //////////////////////////////////////////////////////////////////////////////
  335. class CRuntimeError : public CExceptionWithString
  336. {
  337. public:
  338. //////////////////////////////////////////////////////////////////////////
  339. // Public type definitions
  340. //////////////////////////////////////////////////////////////////////////
  341. typedef CExceptionWithString BaseClass;
  342. //////////////////////////////////////////////////////////////////////////
  343. // Public constructors and destructors
  344. //////////////////////////////////////////////////////////////////////////
  345. // Constructor ( string id overload ).
  346. CRuntimeError(
  347. HRESULT hrErrorCodeIn
  348. , const WCHAR * pcszFileNameIn
  349. , UINT uiLineNumberIn
  350. , UINT uiErrorStringIdIn
  351. ) throw()
  352. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  353. {
  354. }
  355. // Constructor ( character string overload )
  356. CRuntimeError(
  357. HRESULT hrErrorCodeIn
  358. , const WCHAR * pcszFileNameIn
  359. , UINT uiLineNumberIn
  360. , const WCHAR * pcszErrorStringIn
  361. ) throw()
  362. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  363. {
  364. }
  365. // Constructor ( string id & ref string id overload ).
  366. CRuntimeError(
  367. HRESULT hrErrorCodeIn
  368. , const WCHAR * pcszFileNameIn
  369. , UINT uiLineNumberIn
  370. , UINT uiErrorStringIdIn
  371. , UINT uiErrorRefStringIdIn
  372. ) throw()
  373. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn, uiErrorRefStringIdIn )
  374. {
  375. }
  376. // Constructor ( character string & character ref string overload )
  377. CRuntimeError(
  378. HRESULT hrErrorCodeIn
  379. , const WCHAR * pcszFileNameIn
  380. , UINT uiLineNumberIn
  381. , const WCHAR * pcszErrorStringIn
  382. , const WCHAR * pcszErrorRefStringIn
  383. ) throw()
  384. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn, pcszErrorRefStringIn )
  385. {
  386. }
  387. }; //*** class CRuntimeError
  388. //////////////////////////////////////////////////////////////////////////////
  389. //++
  390. //
  391. // class CAbortException
  392. //
  393. // Description:
  394. // This exception is thrown to indicate that the configuration operation
  395. // was aborted.
  396. //
  397. // The accompanying message may be shown to the user and should therefore
  398. // be localized.
  399. //
  400. //--
  401. //////////////////////////////////////////////////////////////////////////////
  402. class CAbortException : public CExceptionWithString
  403. {
  404. public:
  405. //////////////////////////////////////////////////////////////////////////
  406. // Public type definitions
  407. //////////////////////////////////////////////////////////////////////////
  408. typedef CExceptionWithString BaseClass;
  409. //////////////////////////////////////////////////////////////////////////
  410. // Public constructors and destructors
  411. //////////////////////////////////////////////////////////////////////////
  412. // Constructor ( string id overload ).
  413. CAbortException(
  414. HRESULT hrErrorCodeIn
  415. , const WCHAR * pcszFileNameIn
  416. , UINT uiLineNumberIn
  417. , UINT uiErrorStringIdIn
  418. ) throw()
  419. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  420. {
  421. }
  422. // Constructor ( character string overload )
  423. CAbortException(
  424. HRESULT hrErrorCodeIn
  425. , const WCHAR * pcszFileNameIn
  426. , UINT uiLineNumberIn
  427. , const WCHAR * pcszErrorStringIn
  428. ) throw()
  429. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  430. {
  431. }
  432. }; //*** class CAbortException
  433. //////////////////////////////////////////////////////////////////////////////
  434. //++
  435. //
  436. // class CConfigError
  437. //
  438. // Description:
  439. // This class of exceptions is used to signal errors related to cluster
  440. // configuration. For example, an object of this class is thrown if the
  441. // OS version of the computer cannot support the requested configuration
  442. // step.
  443. //
  444. // The accompanying message may be shown to the user and should therefore
  445. // be localized.
  446. //
  447. //--
  448. //////////////////////////////////////////////////////////////////////////////
  449. class CConfigError : public CExceptionWithString
  450. {
  451. public:
  452. //////////////////////////////////////////////////////////////////////////
  453. // Public type definitions
  454. //////////////////////////////////////////////////////////////////////////
  455. typedef CExceptionWithString BaseClass;
  456. //////////////////////////////////////////////////////////////////////////
  457. // Public constructors and destructors
  458. //////////////////////////////////////////////////////////////////////////
  459. // Constructor ( string id overload )
  460. CConfigError(
  461. HRESULT hrErrorCodeIn
  462. , const WCHAR * pcszFileNameIn
  463. , UINT uiLineNumberIn
  464. , UINT uiErrorStringIdIn
  465. ) throw()
  466. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, uiErrorStringIdIn )
  467. {
  468. }
  469. // Constructor ( character string overload )
  470. CConfigError(
  471. HRESULT hrErrorCodeIn
  472. , const WCHAR * pcszFileNameIn
  473. , UINT uiLineNumberIn
  474. , const WCHAR * pcszErrorStringIn
  475. ) throw()
  476. : BaseClass( hrErrorCodeIn, pcszFileNameIn, uiLineNumberIn, pcszErrorStringIn )
  477. {
  478. }
  479. }; //*** class CConfigError