exception.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00034 #include "gpucalc/exception.h"
00035 
00036 #include "gpucalc/log_manager.h"
00037 #include "gpucalc/application.h"
00038 #include "gpucalc/string_util.h"
00039 
00040 namespace gpucalc
00041 {
00042 
00043 
00044  Exception::Exception(int num, const Object & object, const std::string & desc, const std::string & src):
00045    mLine(0), mObject(&object), mNumber(num), mDescription(desc), mSource(src)
00046  {
00047   // Log this error - not any more, allow catchers to do it
00048   //LogManager::getSingleton().logMessage(this->getFullDescription());
00049  }
00050 
00051 
00052  Exception::Exception(int num, const Object & object, const std::string & desc, const std::string & src, const char * typ, const char * fil, long lin):
00053   mLine(lin), mObject(&object), mNumber(num), mTypeName(typ), mDescription(desc), mSource(src), mFile(fil)
00054  {
00055   // Log this error, mask it from debug though since it may be caught and ignored
00056   if (LogManager::getSingletonPtr())
00057   {
00058    LogManager::getSingleton().logMessage(mObject, this->getFullDescription(), LML_Critical, true);
00059   }
00060  }
00061 
00062 
00063  Exception::Exception(const Exception & rhs): std::exception(), mLine(rhs.mLine), mObject(rhs.mObject),
00064   mNumber(rhs.mNumber), mDescription(rhs.mDescription), mSource(rhs.mSource), mFile(rhs.mFile)
00065  {
00066  }
00067 
00068 
00069  void Exception::operator = (const Exception & rhs)
00070  {
00071   mDescription = rhs.mDescription;
00072   mNumber = rhs.mNumber;
00073   mSource = rhs.mSource;
00074   mFile = rhs.mFile;
00075   mLine = rhs.mLine;
00076   mObject = rhs.mObject;
00077   mTypeName = rhs.mTypeName;
00078  }
00079 
00080 
00081  const std::string & Exception::getFullDescription() const
00082  {
00083   if (mFullDesc.empty())
00084   {
00085    std::ostringstream desc;
00086    desc << "EXCEPTION(" << mNumber << ":" << mTypeName << "): "
00087     << mDescription << " in " << mSource;
00088 
00089    if (mLine > 0)
00090    {
00091     desc << " at " << mFile << " (line " << mLine << ")";
00092    }
00093    mFullDesc = desc.str();
00094   }
00095   return mFullDesc;
00096  }
00097 
00098 
00099  int Exception::getNumber() const throw()
00100  {
00101   return mNumber;
00102  }
00103 
00104 
00110  namespace _workaround
00111  {
00112   void DoWarning::doWarning(const Object * obj, const std::string & Description, const std::string & Source,
00113    const std::string & File, int Line)
00114   {
00115    if(!Application::getSingleton().supressWarnings())
00116    {
00117     LogManager::getSingleton().logMessage(obj,
00118      "!!!WARNING!!!\t" + Description + ". " + Source + " at " + File + " (line " + auxillary::StringUtil::toString(Line) + ")",
00119      gpucalc::LML_Critical);
00120    }
00121   }
00122  }
00123 }

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6