comparison engine/core/util/base/exception.h @ 684:4f36c890b1dd

* Merged the 0.3.3dev branche changes to the trunk.
author helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 06 Dec 2010 19:25:27 +0000
parents d266506ff4f9
children
comparison
equal deleted inserted replaced
683:4fe9747d5f88 684:4f36c890b1dd
1 /*************************************************************************** 1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team * 2 * Copyright (C) 2005-2010 by the FIFE team *
3 * http://www.fifengine.de * 3 * http://www.fifengine.net *
4 * This file is part of FIFE. * 4 * This file is part of FIFE. *
5 * * 5 * *
6 * FIFE is free software; you can redistribute it and/or * 6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public * 7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either * 8 * License as published by the Free Software Foundation; either *
22 #ifndef FIFE_EXCEPTION_H 22 #ifndef FIFE_EXCEPTION_H
23 #define FIFE_EXCEPTION_H 23 #define FIFE_EXCEPTION_H
24 24
25 // Standard C++ library includes 25 // Standard C++ library includes
26 #include <string> 26 #include <string>
27 #include <stdexcept>
27 28
28 // 3rd party library includes 29 // 3rd party library includes
29 30
30 // FIFE includes 31 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line 32 // These includes are split up in two parts, separated by one empty line
36 37
37 /** Exception base class. 38 /** Exception base class.
38 * All other exceptions derived from this merely adjust the error string 39 * All other exceptions derived from this merely adjust the error string
39 * to be slightly more specific. 40 * to be slightly more specific.
40 */ 41 */
41 class Exception { 42 class Exception : public std::runtime_error {
42 public: 43 public:
43 /** Constructor. 44 /** Constructor.
44 * @param txt The error mesage to be stored. 45 * @param msg The error mesage to be stored.
45 */ 46 */
46 Exception(const std::string& msg); 47 Exception(const std::string& msg);
47 48
48 /** Destructor. 49 /** Destructor.
49 */ 50 */
50 virtual ~Exception(); 51 virtual ~Exception() throw();
51 52
52 /** Returns the error message. 53 /** Returns the error message.
53 * @return The error message. 54 * @return The error message.
54 */ 55 */
55 std::string getMessage() const; 56 virtual const char* what() const throw();
56 57
57 virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; } 58 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 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 }; 60 };
64 61
65 #define FIFE_EXCEPTION_DECL(_name, _description) \ 62 #define FIFE_EXCEPTION_DECL(_name, _description) \
66 class _name : public Exception { \ 63 class _name : public Exception { \
67 public: \ 64 public: \
68 _name(const std::string& msg) : Exception(msg) {} \ 65 _name(const std::string& msg) : Exception(msg) {} \
69 const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \ 66 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; } \ 67 const std::string& getDescription() const { static const std::string s = _description; return s; } \
71 } 68 }
72 69
73 FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad"); 70 FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad");
74 FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found"); 71 FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found");
75 FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly"); 72 FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly");
76 FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element"); 73 FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element");
77 FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data"); 74 FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data");
82 FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed"); 79 FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed");
83 FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality"); 80 FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality");
84 FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality"); 81 FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality");
85 FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality"); 82 FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality");
86 FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug."); 83 FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug.");
87 84
88 /** @bug The memory allocation in @c std::string might fail, resulting in terminate. */ 85 /** @bug The memory allocation in @c std::string might fail, resulting in terminate. */
89 FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)"); 86 FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)");
90 87
91 88
92 }//FIFE 89 }//FIFE