exceptions.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #pragma once
  17. #include <exception>
  18. #include <string>
  19. class BaseException : public std::exception
  20. {
  21. public:
  22. BaseException(const std::string &s) throw(): m_s(s) {}
  23. ~BaseException() throw() = default;
  24. virtual const char * what() const throw()
  25. {
  26. return m_s.c_str();
  27. }
  28. protected:
  29. std::string m_s;
  30. };
  31. class AlreadyExistsException : public BaseException {
  32. public:
  33. AlreadyExistsException(const std::string &s): BaseException(s) {}
  34. };
  35. class VersionMismatchException : public BaseException {
  36. public:
  37. VersionMismatchException(const std::string &s): BaseException(s) {}
  38. };
  39. class FileNotGoodException : public BaseException {
  40. public:
  41. FileNotGoodException(const std::string &s): BaseException(s) {}
  42. };
  43. class DatabaseException : public BaseException {
  44. public:
  45. DatabaseException(const std::string &s): BaseException(s) {}
  46. };
  47. class SerializationError : public BaseException {
  48. public:
  49. SerializationError(const std::string &s): BaseException(s) {}
  50. };
  51. class PacketError : public BaseException {
  52. public:
  53. PacketError(const std::string &s): BaseException(s) {}
  54. };
  55. class SettingNotFoundException : public BaseException {
  56. public:
  57. SettingNotFoundException(const std::string &s): BaseException(s) {}
  58. };
  59. class ItemNotFoundException : public BaseException {
  60. public:
  61. ItemNotFoundException(const std::string &s): BaseException(s) {}
  62. };
  63. class ServerError : public BaseException {
  64. public:
  65. ServerError(const std::string &s): BaseException(s) {}
  66. };
  67. class ClientStateError : public BaseException {
  68. public:
  69. ClientStateError(const std::string &s): BaseException(s) {}
  70. };
  71. class PrngException : public BaseException {
  72. public:
  73. PrngException(const std::string &s): BaseException(s) {}
  74. };
  75. class ShaderException : public BaseException {
  76. public:
  77. ShaderException(const std::string &s): BaseException(s) {}
  78. };
  79. class ModError : public BaseException {
  80. public:
  81. ModError(const std::string &s): BaseException(s) {}
  82. };
  83. /*
  84. Some "old-style" interrupts:
  85. */
  86. class InvalidNoiseParamsException : public BaseException {
  87. public:
  88. InvalidNoiseParamsException():
  89. BaseException("One or more noise parameters were invalid or require "
  90. "too much memory")
  91. {}
  92. InvalidNoiseParamsException(const std::string &s):
  93. BaseException(s)
  94. {}
  95. };
  96. class InvalidPositionException : public BaseException
  97. {
  98. public:
  99. InvalidPositionException():
  100. BaseException("Somebody tried to get/set something in a nonexistent position.")
  101. {}
  102. InvalidPositionException(const std::string &s):
  103. BaseException(s)
  104. {}
  105. };