exception.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2010 by the FIFE team                              *
00003  *   http://www.fifengine.net                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_EXCEPTION_H
00023 #define FIFE_EXCEPTION_H
00024 
00025 // Standard C++ library includes
00026 #include <string>
00027 #include <stdexcept>
00028 
00029 // 3rd party library includes
00030 
00031 // FIFE includes
00032 // These includes are split up in two parts, separated by one empty line
00033 // First block: files included from the FIFE root src directory
00034 // Second block: files included from the same folder
00035 #include "util/log/logger.h"
00036 
00037 namespace FIFE {
00038 
00043     class Exception : public std::runtime_error {
00044     public:
00048         Exception(const std::string& msg);
00049 
00052         virtual ~Exception() throw();
00053 
00057         virtual const char* what() const throw();
00058 
00059         virtual const std::string& getTypeStr() const { static const std::string s = "Exception"; return s; }
00060         virtual const std::string& getDescription() const { static const std::string s = "Generic FIFE exception"; return s; }
00061 
00062     private:
00063         std::string m_what;
00064     };
00065 
00066     #define FIFE_EXCEPTION_DECL(_name, _description) \
00067     class _name : public Exception { \
00068     public: \
00069         _name(const std::string& msg) : Exception(msg) { Logger _log(LM_EXCEPTION); FL_ERR(_log, what()); } \
00070         const std::string& getTypeStr() const { static const std::string s = #_name; return s; } \
00071         const std::string& getDescription() const { static const std::string s = _description; return s; } \
00072     }
00073 
00074     FIFE_EXCEPTION_DECL(SDLException, "SDL reported something bad");
00075     FIFE_EXCEPTION_DECL(NotFound, "Something was searched, but not found");
00076     FIFE_EXCEPTION_DECL(NotSet, "Something was not set correctly");
00077     FIFE_EXCEPTION_DECL(IndexOverflow, "Someone tried to access a non-existing element");
00078     FIFE_EXCEPTION_DECL(InvalidFormat, "Found invalid data");
00079     FIFE_EXCEPTION_DECL(CannotOpenFile, "File couldn't be opened");
00080     FIFE_EXCEPTION_DECL(InvalidConversion, "Tried an invalid conversion");
00081     FIFE_EXCEPTION_DECL(NotSupported, "This action was not supported");
00082     FIFE_EXCEPTION_DECL(NameClash, "A name or identifier is already in use");
00083     FIFE_EXCEPTION_DECL(Duplicate, "A duplicate item was added, where this is not allowed");
00084     FIFE_EXCEPTION_DECL(ScriptException, "Error related to scripting functionality");
00085     FIFE_EXCEPTION_DECL(EventException, "Error related to event functionality");
00086     FIFE_EXCEPTION_DECL(GuiException, "Error related to gui functionality");
00087     FIFE_EXCEPTION_DECL(InconsistencyDetected, "An inconsistency in FIFE internals was detected. Please report this is a FIFE Bug.");
00088 
00090     FIFE_EXCEPTION_DECL(OutOfMemory, "Buy more ram ;)");
00091 
00092 
00093 }//FIFE
00094 
00095 #endif