MyGUI  3.2.1
MyGUI_Exception.cpp
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #include "MyGUI_Precompiled.h"
00008 #include "MyGUI_Exception.h"
00009 #include "MyGUI_StringUtility.h"
00010 
00011 namespace MyGUI
00012 {
00013 
00014     Exception::Exception(const std::string& _description, const std::string& _source, const char* _file, long _line ) :
00015         mDescription(_description),
00016         mSource(_source),
00017         mFile(_file),
00018         mLine(_line)
00019     {
00020     }
00021 
00022     Exception::Exception(const Exception& _rhs) :
00023         mDescription(_rhs.mDescription),
00024         mSource(_rhs.mSource),
00025         mFile(_rhs.mFile),
00026         mLine(_rhs.mLine),
00027         mFullDesc(_rhs.mFullDesc)
00028     {
00029     }
00030 
00031     Exception::~Exception() throw()
00032     {
00033     }
00034 
00035     Exception& Exception::operator = (const Exception& _rhs)
00036     {
00037         mDescription = _rhs.mDescription;
00038         mSource = _rhs.mSource;
00039         mFile = _rhs.mFile;
00040         mLine = _rhs.mLine;
00041         mFullDesc = _rhs.mFullDesc;
00042         return *this;
00043     }
00044 
00045     const std::string& Exception::getFullDescription() const
00046     {
00047         if (mFullDesc.empty())
00048         {
00049             if ( mLine > 0 )
00050             {
00051                 mFullDesc = utility::toString("MyGUI EXCEPTION : ", mDescription, " in ", mSource, " at ", mFile, " (line ", mLine, ")");
00052             }
00053             else
00054             {
00055                 mFullDesc = utility::toString("MyGUI EXCEPTION : ", mDescription, " in ", mSource);
00056             }
00057         }
00058 
00059         return mFullDesc;
00060     }
00061 
00062     const std::string& Exception::getSource() const
00063     {
00064         return mSource;
00065     }
00066 
00067     const std::string& Exception::getFile() const
00068     {
00069         return mFile;
00070     }
00071 
00072     long Exception::getLine() const
00073     {
00074         return mLine;
00075     }
00076 
00077     const std::string& Exception::getDescription() const
00078     {
00079         return mDescription;
00080     }
00081 
00082     // Override std::exception::what
00083     const char* Exception::what() const throw()
00084     {
00085         return getFullDescription().c_str();
00086     }
00087 
00088 } // namespace MyGUI