Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosException.h

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    00019  *
    00020  */
    00021
    00022 #ifndef KEOS_EXCEPTION_H
    00023 #define KEOS_EXCEPTION_H
    00024
    00025 #include "KeosPrerequisites.h"
    00026
    00027 #define BADDELETE_EXCEPT(p, f, l, a)    {Keos::CBadDelete except((p), (f), (l), (a)); LOG_TMP}
    00028 #define LOADINGFAILED_EXCEPT(f, m, s)   {Keos::CLoadingFailed except((f), (m), (s)); LOG_TMP}
    00029 #define DYNLIB_EXCEPT(f, m, s)          {Keos::CDynLibError except((f), (m), (s)); LOG_TMP}
    00030 #define OUTOFMEMORY_EXCEPT( m, s)       {Keos::COutOfMemory except((m), (s)); LOG_TMP}
    00031 #define UNSUPPORTED_EXCEPT( m, s)       {Keos::CUnsupported except((m), (s)); LOG_TMP}
    00032 #define BADCONVERSION_EXCEPT( m, s)     {Keos::CBadConversion except((m), (s)); LOG_TMP}
    00033
    00034 #define LOG_TMP except.SetFileLine(__FILE__, __LINE__); Keos::ILogger::Log("%s",except.what_short()); throw except;
    00035
    00036 namespace Keos
    00037 {
    00038     //-----------------------------------------------------------------------
    00042     class KEOS_EXPORT CException : public std::exception
    00043     {
    00044     public :
    00045
    00049         CException(const String& strMessage = "");
    00050
    00054         virtual ~CException();
    00055
    00059         virtual const char* what() const;
    00060
    00064         const char* what_short() const;
    00065
    00068         static CException* GetLastException(void) throw();
    00069
    00072         void SetFileLine(String strFile, int nLine);
    00073
    00074     protected :
    00075
    00077         String m_strMessage;
    00079         String m_strShortMessage;
    00081         static CException* ms_pLast;
    00082     };
    00083
    00084
    00085     //-----------------------------------------------------------------------
    00089     struct KEOS_EXPORT CAssertException : public CException
    00090     {
    00096         CAssertException(const String& strFile, int nLine, const String& strMessage);
    00097     };
    00098
    00099     // Define Assert macro
    00100     // allowing of generated an exception if the condition is not verified
    00101     #ifdef KEOS_DEBUG_MODE
    00102     #   define Assert(condition) if (!(condition)) throw CAssertException(__FILE__, __LINE__, "Unsatisfied condition\n\n" #condition)
    00103     #else
    00104     // In no DEBUG_MODE Assert do nothing
    00105         inline void DoNothing(bool) {}
    00106     #   define Assert(condition) DoNothing(!(condition))
    00107     #endif
    00108
    00109
    00110     //-----------------------------------------------------------------------
    00114     struct KEOS_EXPORT CBadDelete : public CException
    00115     {
    00122         CBadDelete(const void* pPtr, const String& strFile, int nLine, bool bNewArray);
    00123     };
    00124
    00125
    00126     //-----------------------------------------------------------------------
    00130     struct KEOS_EXPORT CLoadingFailed : public CException
    00131     {
    00137         CLoadingFailed(const String& strFile, const String& strMessage, const String& strSource);
    00138     };
    00139
    00140     //-----------------------------------------------------------------------
    00144     struct KEOS_EXPORT CDynLibError : public CException
    00145     {
    00151         CDynLibError(const String& strFile, const String& strMessage, const String& strSource);
    00152     };
    00153
    00154
    00155     //-----------------------------------------------------------------------
    00159     struct KEOS_EXPORT COutOfMemory : public CException
    00160     {
    00165         COutOfMemory(const String& strMessage, const String& strSource);
    00166     };
    00167
    00168     //-----------------------------------------------------------------------
    00172     struct KEOS_EXPORT CUnsupported : public CException
    00173     {
    00178         CUnsupported(const String& strFeature, const String& strSource);
    00179     };
    00180
    00181     //-----------------------------------------------------------------------
    00185     struct KEOS_EXPORT CBadConversion : public CException
    00186     {
    00191         CBadConversion(const String& strError, const String& strSource);
    00192     };
    00193
    00194 } // namespace Keos
    00195
    00196 #endif // KEOS_EXCEPTION_H