utility.h: Change Buffer's interface to be more compatible with SharedBuffer's interf...
[oweals/minetest.git] / src / exceptions.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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 #ifndef EXCEPTIONS_HEADER
21 #define EXCEPTIONS_HEADER
22
23 #include <exception>
24
25 class BaseException : public std::exception
26 {
27 public:
28         BaseException(const char *s)
29         {
30                 m_s = s;
31         }
32         virtual const char * what() const throw()
33         {
34                 return m_s;
35         }
36         const char *m_s;
37 };
38
39 class AsyncQueuedException : public BaseException
40 {
41 public:
42         AsyncQueuedException(const char *s):
43                 BaseException(s)
44         {}
45 };
46
47 class NotImplementedException : public BaseException
48 {
49 public:
50         NotImplementedException(const char *s):
51                 BaseException(s)
52         {}
53 };
54
55 class AlreadyExistsException : public BaseException
56 {
57 public:
58         AlreadyExistsException(const char *s):
59                 BaseException(s)
60         {}
61 };
62
63 class VersionMismatchException : public BaseException
64 {
65 public:
66         VersionMismatchException(const char *s):
67                 BaseException(s)
68         {}
69 };
70
71 class FileNotGoodException : public BaseException
72 {
73 public:
74         FileNotGoodException(const char *s):
75                 BaseException(s)
76         {}
77 };
78
79 class SerializationError : public BaseException
80 {
81 public:
82         SerializationError(const char *s):
83                 BaseException(s)
84         {}
85 };
86
87 class LoadError : public BaseException
88 {
89 public:
90         LoadError(const char *s):
91                 BaseException(s)
92         {}
93 };
94
95 class ContainerFullException : public BaseException
96 {
97 public:
98         ContainerFullException(const char *s):
99                 BaseException(s)
100         {}
101 };
102
103 class SettingNotFoundException : public BaseException
104 {
105 public:
106         SettingNotFoundException(const char *s):
107                 BaseException(s)
108         {}
109 };
110
111 class InvalidFilenameException : public BaseException
112 {
113 public:
114         InvalidFilenameException(const char *s):
115                 BaseException(s)
116         {}
117 };
118
119 class ProcessingLimitException : public BaseException
120 {
121 public:
122         ProcessingLimitException(const char *s):
123                 BaseException(s)
124         {}
125 };
126
127 class CommandLineError : public BaseException
128 {
129 public:
130         CommandLineError(const char *s):
131                 BaseException(s)
132         {}
133 };
134
135 class ItemNotFoundException : public BaseException
136 {
137 public:
138         ItemNotFoundException(const char *s):
139                 BaseException(s)
140         {}
141 };
142
143 /*
144         Some "old-style" interrupts:
145 */
146
147 class InvalidPositionException : public BaseException
148 {
149 public:
150         InvalidPositionException():
151                 BaseException("Somebody tried to get/set something in a nonexistent position.")
152         {}
153         InvalidPositionException(const char *s):
154                 BaseException(s)
155         {}
156 };
157
158 class TargetInexistentException : public std::exception
159 {
160         virtual const char * what() const throw()
161         {
162                 return "Somebody tried to refer to something that doesn't exist.";
163         }
164 };
165
166 class NullPointerException : public std::exception
167 {
168         virtual const char * what() const throw()
169         {
170                 return "NullPointerException";
171         }
172 };
173
174 #endif
175