Exception.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *   
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License (LGPL)   *
00008  *   as published by the Free Software Foundation; either version 2 of     *
00009  *   the License, or (at your option) any later version.                   *
00010  *   for detail see the LICENCE text file.                                 *
00011  *                                                                         *
00012  *   FreeCAD is distributed in the hope that it will be useful,            *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with FreeCAD; if not, write to the Free Software        * 
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020  *   USA                                                                   *
00021  *                                                                         *
00022  *   Juergen Riegel 2002                                                   *
00023  ***************************************************************************/
00024 
00025 
00026 #include "PreCompiled.h"
00027 
00028 
00029 #include "Exception.h"
00030 #include "Console.h"
00031 
00032 using namespace Base;
00033 
00034 
00035 TYPESYSTEM_SOURCE(Base::Exception,Base::BaseClass);
00036 
00037 
00038 Exception::Exception(void)
00039 {
00040   _sErrMsg = "FreeCAD Exception";
00041 }
00042 
00043 Exception::Exception(const Exception &inst)
00044  : BaseClass(),_sErrMsg(inst._sErrMsg)
00045 {
00046 }
00047 
00048 
00049 Exception::Exception(const char * sMessage)
00050  : _sErrMsg(sMessage)
00051 {
00052 }
00053 
00054 Exception::Exception(const std::string& sMessage)
00055  : _sErrMsg(sMessage)
00056 {
00057 }
00058 
00059 Exception &Exception::operator=(const Exception &inst)
00060 {
00061   _sErrMsg = inst._sErrMsg;
00062   return *this;
00063 }
00064 
00065 const char* Exception::what(void) const throw()
00066 {
00067     return _sErrMsg.c_str();
00068 }
00069 
00070 void Exception::ReportException (void) const
00071 {
00072     Console().Error("Exception (%s): %s \n",Console().Time(),what());
00073 }
00074 
00075 // ---------------------------------------------------------
00076 
00077 AbortException::AbortException(const char * sMessage)
00078   : Exception( sMessage )
00079 {
00080 }
00081 
00082 AbortException::AbortException()
00083 {
00084     _sErrMsg = "Aborted operation";
00085 }
00086 
00087 AbortException::AbortException(const AbortException &inst)
00088  : Exception(inst)
00089 {
00090 }
00091 
00092 const char* AbortException::what() const throw()
00093 {
00094     return Exception::what();
00095 }
00096 
00097 // ---------------------------------------------------------
00098 
00099 XMLParseException::XMLParseException(const char * sMessage)
00100   : Exception(sMessage)
00101 {
00102 }
00103 
00104 XMLParseException::XMLParseException(const std::string& sMessage)
00105  : Exception(sMessage)
00106 {
00107 }
00108 
00109 XMLParseException::XMLParseException()
00110 {
00111     _sErrMsg = "XML parse exception";
00112 }
00113 
00114 XMLParseException::XMLParseException(const XMLParseException &inst)
00115  : Exception(inst)
00116 {
00117 }
00118 
00119 const char* XMLParseException::what() const throw()
00120 {
00121     return Exception::what();
00122 }
00123 
00124 // ---------------------------------------------------------
00125 
00126 FileException::FileException(const char * sMessage, const char * sFileName)
00127   : Exception( sMessage ),file(sFileName)
00128 {
00129     _sErrMsg += ": ";
00130     _sErrMsg += sFileName;
00131 }
00132 
00133 FileException::FileException(const char * sMessage, const FileInfo& File)
00134   : Exception( sMessage ),file(File)
00135 {
00136     _sErrMsg += ": ";
00137     _sErrMsg += File.fileName();
00138 }
00139 
00140 FileException::FileException()
00141   : Exception( "Unknown file exeption happened" )
00142 {
00143 }
00144 
00145 FileException::FileException(const FileException &inst)
00146   : Exception( inst._sErrMsg.c_str() ),file(inst.file)
00147 {
00148 }
00149 
00150 const char* FileException::what() const throw()
00151 {
00152     return Exception::what();
00153 }
00154 
00155 // ---------------------------------------------------------
00156 
00157 MemoryException::MemoryException()
00158 {
00159     _sErrMsg = "Not enough memory available";
00160 }
00161 
00162 MemoryException::MemoryException(const MemoryException &inst)
00163 #if defined (__GNUC__)
00164  : std::bad_alloc(), Exception(inst) 
00165 #else
00166  : Exception(inst)
00167 #endif
00168 {
00169 }
00170 
00171 #if defined (__GNUC__)
00172 const char* MemoryException::what() const throw()
00173 {
00174     // call what() of Exception, not of std::bad_alloc
00175     return Exception::what();
00176 }
00177 #endif
00178 
00179 // ---------------------------------------------------------
00180 
00181 AccessViolation::AccessViolation()
00182 {
00183     _sErrMsg = "Access violation";
00184 }
00185 
00186 AccessViolation::AccessViolation(const AccessViolation &inst)
00187  : Exception(inst)
00188 {
00189 }
00190 
00191 // ---------------------------------------------------------
00192 
00193 AbnormalProgramTermination::AbnormalProgramTermination()
00194 {
00195     _sErrMsg = "Abnormal program termination";
00196 }
00197 
00198 AbnormalProgramTermination::AbnormalProgramTermination(const AbnormalProgramTermination &inst)
00199  : Exception(inst)
00200 {
00201 }
00202 
00203 // ---------------------------------------------------------
00204 
00205 #if defined(__GNUC__) && defined (FC_OS_LINUX)
00206 #include <stdexcept>
00207 #include <iostream>
00208 
00209 SignalException::SignalException()
00210 {
00211     memset (&new_action, 0, sizeof (new_action));
00212     new_action.sa_handler = throw_signal;
00213     sigemptyset (&new_action.sa_mask);
00214     new_action.sa_flags = 0;
00215     ok = (sigaction (SIGSEGV, &new_action, &old_action) < 0);
00216 #ifdef _DEBUG
00217     std::cout << "Set new signal handler" << std::endl;
00218 #endif
00219 }
00220 
00221 SignalException::~SignalException()
00222 {
00223     sigaction (SIGSEGV, &old_action, NULL);
00224 #ifdef _DEBUG
00225     std::cout << "Restore old signal handler" << std::endl;
00226 #endif
00227 }
00228 
00229 void SignalException::throw_signal(int signum)
00230 {
00231     std::cerr << "SIGSEGV signal raised" << std::endl;
00232     throw std::runtime_error ("throw_signal");
00233 }
00234 #endif
00235 

Generated on Wed Nov 23 19:00:10 2011 for FreeCAD by  doxygen 1.6.1