CmException.h 5.2 KB

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