FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
exception.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 #include "util/log/logger.h"
36 
37 namespace FIFE {
38 
43  class Exception : public std::runtime_error {
44  public:
48  Exception(const std::string& msg);
49 
52  virtual ~Exception() throw();
53 
57  virtual const char* what() const throw();
58 
59  virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; }
60  virtual const std::string& getDescription() const { static const std::string s = "Generic FIFE exception"; return s; }
61  // little helper to change m_what
62  void update();
63 
64  private:
65  std::string m_what;
66  };
67 
68  #define FIFE_EXCEPTION_DECL(_name, _description) \
69  class _name : public Exception { \
70  public: \
71  _name(const std::string& msg) : Exception(msg) { Logger _log(LM_EXCEPTION); update(); FL_ERR(_log, what()); } \
72  const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \
73  const std::string& getDescription() const { static const std::string s = _description; return s; } \
74  }
75 
76  FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad");
77  FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found");
78  FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly");
79  FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element");
80  FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data");
81  FIFE_EXCEPTION_DECL(CannotOpenFile, "File couldn't be opened");
82  FIFE_EXCEPTION_DECL(InvalidConversion, "Tried an invalid conversion");
83  FIFE_EXCEPTION_DECL(NotSupported, "This action was not supported");
84  FIFE_EXCEPTION_DECL(NameClash, "A name or identifier is already in use");
85  FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed");
86  FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality");
87  FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality");
88  FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality");
89  FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug.");
90 
92  FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)");
93 
94 
95 }//FIFE
96 
97 #endif
virtual const char * what() const
Returns the error message.
Definition: exception.cpp:41
virtual ~Exception()
Destructor.
Definition: exception.cpp:39
Exception base class.
Definition: exception.h:43
Exception(const std::string &msg)
Constructor.
Definition: exception.cpp:36
virtual const std::string & getDescription() const
Definition: exception.h:60
FIFE_EXCEPTION_DECL(SDLException,"SDL reported something bad")
virtual const std::string & getTypeStr() const
Definition: exception.h:59
std::string m_what
Definition: exception.h:65