exceptions.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #ifndef EXCEPTIONS_HEADER
  17. #define EXCEPTIONS_HEADER
  18. #include <exception>
  19. #include <string>
  20. class BaseException : public std::exception
  21. {
  22. public:
  23. BaseException(const std::string &s) throw()
  24. {
  25. m_s = s;
  26. }
  27. ~BaseException() throw() {}
  28. virtual const char * what() const throw()
  29. {
  30. return m_s.c_str();
  31. }
  32. protected:
  33. std::string m_s;
  34. };
  35. class AsyncQueuedException : public BaseException {
  36. public:
  37. AsyncQueuedException(const std::string &s): BaseException(s) {}
  38. };
  39. class NotImplementedException : public BaseException {
  40. public:
  41. NotImplementedException(const std::string &s): BaseException(s) {}
  42. };
  43. class AlreadyExistsException : public BaseException {
  44. public:
  45. AlreadyExistsException(const std::string &s): BaseException(s) {}
  46. };
  47. class VersionMismatchException : public BaseException {
  48. public:
  49. VersionMismatchException(const std::string &s): BaseException(s) {}
  50. };
  51. class FileNotGoodException : public BaseException {
  52. public:
  53. FileNotGoodException(const std::string &s): BaseException(s) {}
  54. };
  55. class SerializationError : public BaseException {
  56. public:
  57. SerializationError(const std::string &s): BaseException(s) {}
  58. };
  59. class LoadError : public BaseException {
  60. public:
  61. LoadError(const std::string &s): BaseException(s) {}
  62. };
  63. class ContainerFullException : public BaseException {
  64. public:
  65. ContainerFullException(const std::string &s): BaseException(s) {}
  66. };
  67. class SettingNotFoundException : public BaseException {
  68. public:
  69. SettingNotFoundException(const std::string &s): BaseException(s) {}
  70. };
  71. class InvalidFilenameException : public BaseException {
  72. public:
  73. InvalidFilenameException(const std::string &s): BaseException(s) {}
  74. };
  75. class ProcessingLimitException : public BaseException {
  76. public:
  77. ProcessingLimitException(const std::string &s): BaseException(s) {}
  78. };
  79. class CommandLineError : public BaseException {
  80. public:
  81. CommandLineError(const std::string &s): BaseException(s) {}
  82. };
  83. class ItemNotFoundException : public BaseException {
  84. public:
  85. ItemNotFoundException(const std::string &s): BaseException(s) {}
  86. };
  87. class ServerError : public BaseException {
  88. public:
  89. ServerError(const std::string &s): BaseException(s) {}
  90. };
  91. // Only used on Windows (SEH)
  92. class FatalSystemException : public BaseException {
  93. public:
  94. FatalSystemException(const std::string &s): BaseException(s) {}
  95. };
  96. class ClientStateError : public BaseException {
  97. public:
  98. ClientStateError(std::string s): BaseException(s) {}
  99. };
  100. /*
  101. Some "old-style" interrupts:
  102. */
  103. class InvalidPositionException : public BaseException
  104. {
  105. public:
  106. InvalidPositionException():
  107. BaseException("Somebody tried to get/set something in a nonexistent position.")
  108. {}
  109. InvalidPositionException(const std::string &s):
  110. BaseException(s)
  111. {}
  112. };
  113. class TargetInexistentException : public std::exception
  114. {
  115. virtual const char * what() const throw()
  116. {
  117. return "Somebody tried to refer to something that doesn't exist.";
  118. }
  119. };
  120. class NullPointerException : public std::exception
  121. {
  122. virtual const char * what() const throw()
  123. {
  124. return "NullPointerException";
  125. }
  126. };
  127. #endif