CmException.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include <boost/static_assert.hpp>
  4. #include <boost/type_traits.hpp>
  5. #if defined(_MSC_VER)
  6. #undef __PRETTY_FUNCTION__
  7. #define __PRETTY_FUNCTION__ __FUNCSIG__
  8. #endif
  9. namespace CamelotFramework
  10. {
  11. class CM_UTILITY_EXPORT Exception : public std::exception
  12. {
  13. protected:
  14. long mLine;
  15. String mTypeName;
  16. String mDescription;
  17. String mSource;
  18. String mFile;
  19. mutable String mFullDesc;
  20. public:
  21. /** Default constructor.
  22. */
  23. Exception(const char* type, const String& description, const String& source);
  24. /** Advanced constructor.
  25. */
  26. Exception(const char* type, const String& description, const String& source, const char* file, long line);
  27. /** Copy constructor.
  28. */
  29. Exception(const Exception& rhs);
  30. /// Needed for compatibility with std::exception
  31. ~Exception() throw() {}
  32. /** Assignment operator.
  33. */
  34. void operator = (const Exception& rhs);
  35. /** Returns a string with the full description of this error.
  36. @remarks
  37. The description contains the error number, the description
  38. supplied by the thrower, what routine threw the exception,
  39. and will also supply extra platform-specific information
  40. where applicable. For example - in the case of a rendering
  41. library error, the description of the error will include both
  42. the place in which OGRE found the problem, and a text
  43. description from the 3D rendering library, if available.
  44. */
  45. virtual const String& getFullDescription() const;
  46. /** Gets the source function.
  47. */
  48. virtual const String& getSource() const { return mSource; }
  49. /** Gets source file name.
  50. */
  51. virtual const String& getFile() const { return mFile; }
  52. /** Gets line number.
  53. */
  54. virtual long getLine() const { return mLine; }
  55. /** Returns a string with only the 'description' field of this exception. Use
  56. getFullDescriptionto get a full description of the error including line number,
  57. error number and what function threw the exception.
  58. */
  59. virtual const String& getDescription(void) const { return mDescription; }
  60. /// Override std::exception::what
  61. const char* what() const throw() { return getFullDescription().c_str(); }
  62. };
  63. class CM_UTILITY_EXPORT NotImplementedException : public Exception
  64. {
  65. public:
  66. NotImplementedException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  67. : Exception("NotImplementedException", inDescription, inSource, inFile, inLine) {}
  68. };
  69. class CM_UTILITY_EXPORT FileNotFoundException : public Exception
  70. {
  71. public:
  72. FileNotFoundException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  73. : Exception("FileNotFoundException", inDescription, inSource, inFile, inLine) {}
  74. };
  75. class CM_UTILITY_EXPORT IOException : public Exception
  76. {
  77. public:
  78. IOException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  79. : Exception("IOException", inDescription, inSource, inFile, inLine) {}
  80. };
  81. class CM_UTILITY_EXPORT InvalidStateException : public Exception
  82. {
  83. public:
  84. InvalidStateException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  85. : Exception("InvalidStateException", inDescription, inSource, inFile, inLine) {}
  86. };
  87. class CM_UTILITY_EXPORT InvalidParametersException : public Exception
  88. {
  89. public:
  90. InvalidParametersException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  91. : Exception("InvalidParametersException", inDescription, inSource, inFile, inLine) {}
  92. };
  93. class CM_UTILITY_EXPORT ItemIdentityException : public Exception
  94. {
  95. public:
  96. ItemIdentityException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  97. : Exception("ItemIdentityException", inDescription, inSource, inFile, inLine) {}
  98. };
  99. class CM_UTILITY_EXPORT InternalErrorException : public Exception
  100. {
  101. public:
  102. InternalErrorException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  103. : Exception("InternalErrorException", inDescription, inSource, inFile, inLine) {}
  104. };
  105. class CM_UTILITY_EXPORT RenderingAPIException : public Exception
  106. {
  107. public:
  108. RenderingAPIException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  109. : Exception("RenderingAPIException", inDescription, inSource, inFile, inLine) {}
  110. };
  111. class CM_UTILITY_EXPORT RuntimeAssertionException : public Exception
  112. {
  113. public:
  114. RuntimeAssertionException(const String& inDescription, const String& inSource, const char* inFile, long inLine)
  115. : Exception("RuntimeAssertionException", inDescription, inSource, inFile, inLine) {}
  116. };
  117. #ifndef CM_EXCEPT
  118. #define CM_EXCEPT(type, desc) \
  119. { \
  120. BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotFramework::Exception, type##>::value), "Invalid exception type (" #type ") for CM_EXCEPT macro. It needs to derive from CamelotFramework::Exception."); \
  121. throw type##(desc, __PRETTY_FUNCTION__, __FILE__, __LINE__); \
  122. }
  123. #endif
  124. }