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