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.

289 lines
7.7 KiB

  1. #ifndef _INC_DSKQUOTA_EXCEPT_H
  2. #define _INC_DSKQUOTA_EXCEPT_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: except.h
  5. Description: Basic exception class hierarchy.
  6. I shamelessly based this on the MFC exception hierarchy.
  7. CException
  8. CMemoryException - i.e. "Out of memory", "invalid index"
  9. CFileException - i.e. "device IO error"
  10. CSyncException - i.e. "mutext abandoned"
  11. CResourceException - i.e. "resource not found in image"
  12. COleException - i.e. "some critical OLE error"
  13. CNotSupportedException - i.e. "function not supported"
  14. Revision History:
  15. Date Description Programmer
  16. -------- --------------------------------------------------- ----------
  17. 09/16/97 Initial creation. BrianAu
  18. */
  19. ///////////////////////////////////////////////////////////////////////////////
  20. #ifndef _WINDOWS_
  21. # include <windows.h>
  22. #endif
  23. //
  24. // Very naive string implementation. Just need something simple to hold
  25. // strings in exception objects when necessary.
  26. // Ensures proper cleanup on dtor.
  27. // Can't use CString here (I wanted to) because that creates a circular
  28. // reference condition between strclass.h and except.h
  29. //
  30. class CExceptionString
  31. {
  32. public:
  33. explicit CExceptionString(LPCTSTR pszText = TEXT(""));
  34. ~CExceptionString(void)
  35. { delete[] m_pszText; }
  36. CExceptionString(const CExceptionString& rhs);
  37. CExceptionString& operator = (const CExceptionString& rhs);
  38. const TCHAR * const GetTextPtr(void) const
  39. { return m_pszText; }
  40. private:
  41. LPTSTR m_pszText;
  42. LPTSTR Dup(LPCTSTR psz);
  43. };
  44. //
  45. // Base class for all exceptions.
  46. //
  47. class CException
  48. {
  49. public:
  50. enum reason { none };
  51. explicit CException(DWORD r) : m_reason(r) { }
  52. DWORD Reason(void) const { return m_reason; }
  53. #if DBG
  54. virtual LPCTSTR NameText(void) const
  55. { return TEXT("CException"); }
  56. virtual LPCTSTR ReasonText(void) const
  57. { return TEXT("Unknown"); }
  58. #endif // DBG
  59. private:
  60. DWORD m_reason;
  61. };
  62. //
  63. // Exception class representing different "bad" things associated
  64. // with memory use.
  65. //
  66. class CMemoryException : public CException
  67. {
  68. public:
  69. enum reason { alloc, // Memory allocation failure.
  70. overflow, // Memory overflow.
  71. index, // Bad index value.
  72. range, // Value overrange for data type.
  73. pointer, // Bad pointer (i.e. NULL).
  74. num_reasons
  75. };
  76. explicit CMemoryException(reason r) : CException((DWORD)r) { }
  77. #if DBG
  78. virtual LPCTSTR NameText(void) const
  79. { return TEXT("CMemoryException"); }
  80. virtual LPCTSTR ReasonText(void) const
  81. { return m_pszReasons[Reason()]; }
  82. private:
  83. static LPCTSTR m_pszReasons[num_reasons];
  84. #endif // DBG
  85. };
  86. class CAllocException : private CMemoryException
  87. {
  88. public:
  89. CAllocException(void) : CMemoryException(CMemoryException::alloc) { }
  90. #if DBG
  91. virtual LPCTSTR NameText(void) const
  92. { return TEXT("CAllocException"); }
  93. virtual LPCTSTR ReasonText(void) const
  94. { return CMemoryException::ReasonText(); }
  95. #endif // DBG
  96. };
  97. //
  98. // Exception class representing file I/O errors.
  99. //
  100. class CFileException : public CException
  101. {
  102. public:
  103. enum reason { create, // Can't create file.
  104. read, // Can't read file.
  105. write, // Can't write file.
  106. diskfull, // Disk is full.
  107. access, // No access.
  108. device, // Device write error.
  109. num_reasons
  110. };
  111. CFileException(reason r, LPCTSTR pszFile, DWORD dwIoError)
  112. : CException((DWORD)r),
  113. m_strFile(pszFile),
  114. m_dwIoError(dwIoError) { }
  115. #if DBG
  116. virtual LPCTSTR NameText(void) const
  117. { return TEXT("CFileException"); }
  118. virtual LPCTSTR ReasonText(void) const
  119. { return m_pszReasons[Reason()]; }
  120. #endif // DBG
  121. const TCHAR * const FileName(void) const { return m_strFile.GetTextPtr(); }
  122. DWORD IoError(void) const { return m_dwIoError; }
  123. private:
  124. DWORD m_dwIoError;
  125. CExceptionString m_strFile;
  126. #if DBG
  127. static LPCTSTR m_pszReasons[num_reasons];
  128. #endif // DBG
  129. };
  130. //
  131. // Thread synchronization object exception.
  132. //
  133. class CSyncException : public CException
  134. {
  135. public:
  136. enum object { mutex, critsect, semaphore, event, thread, process, num_objects };
  137. enum reason { create, timeout, abandoned, num_reasons };
  138. CSyncException(object obj, reason r)
  139. : CException(r),
  140. m_object(obj) { }
  141. #if DBG
  142. virtual LPCTSTR NameText(void) const
  143. { return TEXT("CSyncException"); }
  144. virtual LPCTSTR ReasonText(void) const
  145. { return m_pszReasons[Reason()]; }
  146. virtual LPCTSTR ObjectText(void) const
  147. { return m_pszObjects[Object()]; }
  148. #endif // DBG
  149. object Object(void) const { return m_object; }
  150. private:
  151. object m_object;
  152. #if DBG
  153. static LPCTSTR m_pszReasons[num_reasons];
  154. static LPCTSTR m_pszObjects[num_objects];
  155. #endif // DBG
  156. };
  157. //
  158. // Windows resource exception.
  159. //
  160. class CResourceException : public CException
  161. {
  162. public:
  163. enum type { accelerator,
  164. anicursor,
  165. aniicon,
  166. bitmap,
  167. cursor,
  168. dialog,
  169. font,
  170. fontdir,
  171. group_cursor,
  172. group_icon,
  173. icon,
  174. menu,
  175. messagetable,
  176. rcdata,
  177. string,
  178. version,
  179. num_reasons };
  180. CResourceException(type t, HINSTANCE hInstance, UINT uResId)
  181. : CException(CException::none),
  182. m_type(t),
  183. m_uResId(uResId),
  184. m_hInstance(hInstance) { }
  185. #if DBG
  186. virtual LPCTSTR NameText(void) const
  187. { return TEXT("CResourceException"); }
  188. virtual LPCTSTR ReasonText(void) const;
  189. #endif // DBG
  190. HINSTANCE Module(void) const { return m_hInstance; }
  191. enum type Type(void) const { return m_type; }
  192. private:
  193. enum type m_type;
  194. UINT m_uResId;
  195. HINSTANCE m_hInstance;
  196. #if DBG
  197. static LPCTSTR m_pszReasons[num_reasons];
  198. #endif // DBG
  199. };
  200. class COleException : public CException
  201. {
  202. public:
  203. explicit COleException(HRESULT hr)
  204. : CException(CException::none),
  205. m_hr(hr) { }
  206. HRESULT Result(void) const { return m_hr; }
  207. #if DBG
  208. virtual LPCTSTR NameText(void) const
  209. { return TEXT("COleException"); }
  210. virtual LPCTSTR ReasonText(void) const
  211. { return TEXT("not applicable"); }
  212. #endif // DBG
  213. private:
  214. HRESULT m_hr;
  215. };
  216. //
  217. // Some requested operation is not supported.
  218. //
  219. class CNotSupportedException : public CException
  220. {
  221. public:
  222. CNotSupportedException(void) : CException(CException::none) { }
  223. #if DBG
  224. virtual LPCTSTR NameText(void) const
  225. { return TEXT("CNotSupportedException"); }
  226. virtual LPCTSTR ReasonText(void) const
  227. { return TEXT("not applicable"); }
  228. #endif // DBG
  229. };
  230. #endif // _INC_DSKQUOTA_EXCEPT_H