FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
exception.h
1 /***************************************************************************
2  * Copyright (C) 2005-2010 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, 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 #include <stdexcept>
28 
29 // 3rd party library includes
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 
36 namespace FIFE {
37 
42  class Exception : public std::runtime_error {
43  public:
47  Exception(const std::string& msg);
48 
51  virtual ~Exception() throw();
52 
56  virtual const char* what() const throw();
57 
58  virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; }
59  virtual const std::string& getDescription() const { static const std::string s = "Generic FIFE exception"; return s; }
60  };
61 
62  #define FIFE_EXCEPTION_DECL(_name, _description) \
63  class _name : public Exception { \
64  public: \
65  _name(const std::string& msg) : Exception(msg) {} \
66  const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \
67  const std::string& getDescription() const { static const std::string s = _description; return s; } \
68  }
69 
70  FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad");
71  FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found");
72  FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly");
73  FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element");
74  FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data");
75  FIFE_EXCEPTION_DECL(CannotOpenFile, "File couldn't be opened");
76  FIFE_EXCEPTION_DECL(InvalidConversion, "Tried an invalid conversion");
77  FIFE_EXCEPTION_DECL(NotSupported, "This action was not supported");
78  FIFE_EXCEPTION_DECL(NameClash, "A name or identifier is already in use");
79  FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed");
80  FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality");
81  FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality");
82  FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality");
83  FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug.");
84 
86  FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)");
87 
88 
89 }//FIFE
90 
91 #endif