Mercurial > fife-parpg
comparison engine/core/util/base/exception.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 #ifndef FIFE_EXCEPTION_H | |
23 #define FIFE_EXCEPTION_H | |
24 | |
25 // Standard C++ library includes | |
26 #include <string> | |
27 | |
28 // 3rd party library includes | |
29 | |
30 // FIFE includes | |
31 // These includes are split up in two parts, separated by one empty line | |
32 // First block: files included from the FIFE root src directory | |
33 // Second block: files included from the same folder | |
34 | |
35 namespace FIFE { | |
36 | |
37 /** Exception base class. | |
38 * All other exceptions derived from this merely adjust the error string | |
39 * to be slightly more specific. | |
40 */ | |
41 class Exception { | |
42 public: | |
43 /** Constructor. | |
44 * @param txt The error mesage to be stored. | |
45 */ | |
46 Exception(const std::string& msg); | |
47 | |
48 /** Destructor. | |
49 */ | |
50 virtual ~Exception(); | |
51 | |
52 /** Returns the error message. | |
53 * @return The error message. | |
54 */ | |
55 std::string getMessage() const; | |
56 | |
57 virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; } | |
58 virtual const std::string& getDescription() const { static const std::string s = "Generic FIFE exception"; return s; } | |
59 | |
60 private: | |
61 // The error string. | |
62 std::string m_message; | |
63 }; | |
64 | |
65 #define FIFE_EXCEPTION_DECL(_name, _description) \ | |
66 class _name : public Exception { \ | |
67 public: \ | |
68 _name(const std::string& msg) : Exception(msg) {} \ | |
69 const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \ | |
70 const std::string& getDescription() const { static const std::string s = _description; return s; } \ | |
71 } | |
72 | |
73 FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad"); | |
74 FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found"); | |
75 FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly"); | |
76 FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element"); | |
77 FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data"); | |
78 FIFE_EXCEPTION_DECL(CannotOpenFile, "File couldn't be opened"); | |
79 FIFE_EXCEPTION_DECL(InvalidConversion, "Tried an invalid conversion"); | |
80 FIFE_EXCEPTION_DECL(NotSupported, "This action was not supported"); | |
81 FIFE_EXCEPTION_DECL(NameClash, "A name or identifier is already in use"); | |
82 FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed"); | |
83 FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality"); | |
84 FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality"); | |
85 FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality"); | |
86 | |
87 /** @bug The memory allocation in @c std::string might fail, resulting in terminate. */ | |
88 FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)"); | |
89 | |
90 | |
91 }//FIFE | |
92 | |
93 #endif |