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.

120 lines
3.8 KiB

  1. //
  2. // MODULE: BaseException.
  3. //
  4. // PURPOSE: interface for CBaseException class.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Oleg Kalosha
  9. //
  10. // ORIGINAL DATE: 9-24-98
  11. //
  12. // NOTES:
  13. //
  14. // Version Date By Comments
  15. //--------------------------------------------------------------------
  16. // V3.0 9-24-98 RAB Broke class out of stateless.h and now derive from STL exception.
  17. //
  18. #ifndef __BASEEXCEPTION_H_
  19. #define __BASEEXCEPTION_H_
  20. #if _MSC_VER >= 1000
  21. #pragma once
  22. #endif // _MSC_VER >= 1000
  23. #include "apgtsstr.h"
  24. #include <exception>
  25. ////////////////////////////////////////////////////////////////////////////////////
  26. // utility class to strip out the path of a filename and append the line number.
  27. /////////////////////////////////////////////////////////////////////////////////////
  28. class CBuildSrcFileLinenoStr
  29. {
  30. public:
  31. // source_file is LPCSTR rather than LPCTSTR because __FILE__ is char[35]
  32. CBuildSrcFileLinenoStr( LPCSTR source_file, int line );
  33. virtual ~CBuildSrcFileLinenoStr() {}
  34. CString GetSrcFileLineStr() const;
  35. private:
  36. CString m_strFileLine; // source file (__FILE__) and line number (__LINE__) of code throwing exception (__FILE__)
  37. };
  38. ////////////////////////////////////////////////////////////////////////////////////
  39. // basic exception class
  40. /////////////////////////////////////////////////////////////////////////////////////
  41. class CBaseException : public exception
  42. {
  43. public:
  44. // source_file is LPCSTR rather than LPCTSTR because __FILE__ is char[35]
  45. CBaseException( LPCSTR source_file, int line );
  46. virtual ~CBaseException() {}
  47. CString GetSrcFileLineStr() const;
  48. private:
  49. CString m_strFileLine; // source file (__FILE__) and line number (__LINE__) of code throwing exception (__FILE__)
  50. };
  51. ////////////////////////////////////////////////////////////////////////////////////
  52. // Class to handle general exception conditions.
  53. // Constructor takes a source file name, source file line number, and a developer-defined
  54. // error code and error message.
  55. class CGeneralException : public CBaseException
  56. {
  57. public:
  58. enum eErr
  59. {
  60. eErrMemAllocFatal,
  61. eErrMemAllocNonFatal
  62. } m_eErr;
  63. public:
  64. CGeneralException( LPCSTR srcFile, // Source file from which the exception was thrown.
  65. int srcLineNo, // Source line from which the exception was thrown.
  66. LPCTSTR strErrMsg, // Developer defined error message for the exception.
  67. DWORD nErrCode // Developer defined error code for the exception.
  68. );;
  69. virtual ~CGeneralException() {}
  70. DWORD GetErrorCode() const;
  71. CString GetErrorMsg() const;
  72. private:
  73. CString m_strErrMsg; // Developer-defined exception error message.
  74. DWORD m_nErrCode; // Developer-defined exception error code.
  75. };
  76. ////////////////////////////////////////////////////////////////////////////////////
  77. ////////////////////////////////////////////////////////////////////////////////////
  78. // Class to handle general system call generated exception conditions.
  79. // Constructor takes a source file name, source file line number, and a developer-defined
  80. // error code and error message. Automatically generates an internal string from the last
  81. // system error code.
  82. class CGenSysException : public CGeneralException
  83. {
  84. public:
  85. CGenSysException( LPCSTR srcFile, // Source file from which the exception was thrown.
  86. // LPCSTR rather than LPCTSTR because __FILE__ is char[35]
  87. int srcLineNo, // Source line from which the exception was thrown.
  88. LPCTSTR strErrMsg, // Developer defined error message for the exception.
  89. DWORD nErrCode // Developer defined error code for the exception.
  90. );
  91. virtual ~CGenSysException() {}
  92. CString GetSystemErrStr() const;
  93. private:
  94. CString m_strSystemErr; // String generated from the last system error code.
  95. };
  96. ////////////////////////////////////////////////////////////////////////////////////
  97. #endif
  98. //
  99. // EOF.
  100. //