KeosException.cpp

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 #include "KeosException.h"
00023 #include "KeosString.h"
00024 
00025 namespace Keos
00026 {
00027   //=======================================================================
00028   // CException implementation
00029   //=======================================================================
00030 
00031   CException* CException::ms_pLast = NULL;
00032 
00033   //-----------------------------------------------------------------------
00034   CException::CException(const String& strMessage) :
00035       m_strMessage(strMessage)
00036   {
00037     ms_pLast = this;
00038     m_strShortMessage = "EXCEPTION undefined";
00039   }
00040 
00041   //-----------------------------------------------------------------------
00042   CException::~CException()
00043   {}
00044 
00045   //-----------------------------------------------------------------------
00046   const char* CException::what() const
00047   {
00048     return m_strMessage.c_str();
00049   }
00050 
00051   //-----------------------------------------------------------------------
00052   const char* CException::what_short() const
00053   {
00054     return m_strShortMessage.c_str();
00055   }
00056 
00057   //-----------------------------------------------------------------------
00058   CException* CException::GetLastException(void) throw()
00059   {
00060     return ms_pLast;
00061   }
00062 
00063   //-----------------------------------------------------------------------
00064   void CException::SetFileLine(String strFile, int nLine)
00065   {
00066     std::ostringstream oss;
00067     oss << m_strMessage << std::endl << "File: '" << strFile << "' Line: "
00068     << CStringConverter::ToString(nLine);
00069     m_strMessage = oss.str();
00070 
00071     std::ostringstream oss2;
00072     oss2 << m_strShortMessage << " (" << strFile << ", L"
00073     << CStringConverter::ToString(nLine) << ")";
00074     m_strShortMessage = oss2.str();
00075   }
00076 
00077 
00078   //=======================================================================
00079   // CAssertException implementation
00080   //=======================================================================
00081 
00082   //-----------------------------------------------------------------------
00083   CAssertException::CAssertException(const String& strFile, int nLine, const String& strMessage)
00084   {
00085     // Format error message
00086     std::ostringstream oss;
00087     oss << strMessage << std::endl;
00088     oss << strFile << " (" << nLine << ")";
00089 
00090     m_strMessage = oss.str();
00091   }
00092 
00093 
00094   //=======================================================================
00095   // CBadDelete implementation
00096   //=======================================================================
00097 
00098   //-----------------------------------------------------------------------
00099   CBadDelete::CBadDelete(const void* pPtr, const String& strFile, int nLine, bool bNewArray)
00100   {
00101     // Format error message
00102     std::ostringstream oss;
00103     oss << "EXCEPTION CBadDelete --> "
00104     << (bNewArray ? "new[] / delete" :  "new / delete[]")
00105     << " detectee" << std::endl
00106     << "Address : 0x" << pPtr << std::endl
00107     << "Source file : " << strFile << " (" << nLine << ")";
00108 
00109     m_strMessage = oss.str();
00110 
00111     std::ostringstream oss2;
00112     oss2 << "EXCEPTION CBadDelete --> "
00113     << (bNewArray ? "new[] / delete" :  "new / delete[]")
00114     << " detectee";
00115 
00116     m_strShortMessage = oss2.str();
00117   }
00118 
00119 
00120   //=======================================================================
00121   // CLoadingFailed implementation
00122   //=======================================================================
00123 
00124   //-----------------------------------------------------------------------
00125   CLoadingFailed::CLoadingFailed(const String& strFile, const String& strMessage, const String& strSource)
00126   {
00127     // Format error message
00128     std::ostringstream oss;
00129     oss << "EXCEPTION CLoadingFailed in " << strSource << std::endl
00130     << "Error in the load of '" << strFile << "'" << std::endl << strMessage;
00131 
00132     m_strMessage = oss.str();
00133 
00134     std::ostringstream oss2;
00135     oss2 << "EXCEPTION CLoadingFailed in " << strSource << " --> "
00136     << "Error in the load of '" << strFile << "'";
00137 
00138     m_strShortMessage = oss2.str();
00139   }
00140 
00141 
00142   //=======================================================================
00143   // CDynLibError implementation
00144   //=======================================================================
00145 
00146   //-----------------------------------------------------------------------
00147   CDynLibError::CDynLibError(const String& strFile, const String& strMessage, const String& strSource)
00148   {
00149     // Format error message
00150     std::ostringstream oss;
00151     oss << "EXCEPTION CDynLibError in " << strSource << std::endl
00152     << "Error in the library '" << strFile << "'" << std::endl << strMessage;
00153 
00154     m_strMessage = oss.str();
00155 
00156     std::ostringstream oss2;
00157     oss2 << "EXCEPTION CDynLibError in " << strSource << " --> "
00158     << "Error in the library '" << strFile << "'";
00159 
00160     m_strShortMessage = oss2.str();
00161   }
00162 
00163 
00164   //=======================================================================
00165   // COutOfMemory implementation
00166   //=======================================================================
00167 
00168   //-----------------------------------------------------------------------
00169   COutOfMemory::COutOfMemory(const String& strMessage, const String& strSource)
00170   {
00171     // Format error message
00172     std::ostringstream oss;
00173     oss << "EXCEPTION COutOfMemory in " << strSource << std::endl << strMessage;
00174 
00175     m_strMessage = oss.str();
00176 
00177     std::ostringstream oss2;
00178     oss2 << "EXCEPTION COutOfMemory in " << strSource;
00179 
00180     m_strShortMessage = oss2.str();
00181   }
00182 
00183   //=======================================================================
00184   // CUnsupported implementation
00185   //=======================================================================
00186 
00187   //-----------------------------------------------------------------------
00188   CUnsupported::CUnsupported(const String& strFeature, const String& strSource)
00189   {
00190     // Format error message
00191     std::ostringstream oss;
00192     oss << "EXCEPTION CUnsupported in " << strSource << std::endl
00193     << "Unsupported feature : " << strFeature;
00194 
00195     m_strMessage = oss.str();
00196 
00197     std::ostringstream oss2;
00198     oss2 << "EXCEPTION CUnsupported in " << strSource << " --> "
00199     << "Unsupported feature : " << strFeature;
00200 
00201     m_strShortMessage = oss2.str();
00202   }
00203 
00204   //=======================================================================
00205   // CBadConversion implementation
00206   //=======================================================================
00207 
00208   //-----------------------------------------------------------------------
00209   CBadConversion::CBadConversion(const String& strError, const String& strSource)
00210   {
00211     // Format error message
00212     std::ostringstream oss;
00213     oss << "EXCEPTION CBadConversion in " << strSource << std::endl
00214     << "Conversion error : " << strError;
00215 
00216     m_strMessage = oss.str();
00217 
00218     std::ostringstream oss2;
00219     oss2 << "EXCEPTION CBadConversion in " << strSource << " --> "
00220     << "Conversion error : " << strError;
00221 
00222     m_strShortMessage = oss2.str();
00223   }
00224 } // namespace Keos

Generated on Fri Mar 9 14:29:02 2007 for Keos by  doxygen 1.5.1-p1