Exception.h

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 #ifndef BASE_EXCEPTION_H
00027 #define BASE_EXCEPTION_H
00028 
00029 #include <exception>
00030 #include <string>
00031 #include <signal.h>
00032 #include "FileInfo.h"
00033 #include "BaseClass.h"
00034 
00035 namespace Base
00036 {
00037 
00038 class BaseExport Exception : public BaseClass
00039 {
00040   TYPESYSTEM_HEADER();
00041 
00042 public:
00043   Exception(const char * sMessage);
00044   Exception(const std::string& sMessage);
00045   Exception(void);
00046   Exception(const Exception &inst);
00047   virtual ~Exception() throw() {}
00048 
00049   Exception &operator=(const Exception &inst);
00050   virtual const char* what(void) const throw();
00051   void ReportException (void) const;
00052   inline void setMessage(const char * sMessage);
00053   inline void setMessage(const std::string& sMessage);
00054   
00055 protected:
00056   std::string _sErrMsg;
00057 };
00058 
00059 
00064 class BaseExport AbortException : public Exception
00065 {
00066 public:
00068   AbortException(const char * sMessage);
00070   AbortException();
00072   AbortException(const AbortException &inst);
00074   virtual ~AbortException() throw() {}
00076   virtual const char* what() const throw();
00077 };
00078 
00083 class BaseExport XMLParseException : public Exception
00084 {
00085 public:
00087   XMLParseException(const char * sMessage);
00089   XMLParseException(const std::string& sMessage);
00091   XMLParseException();
00093   XMLParseException(const XMLParseException &inst);
00095   virtual ~XMLParseException() throw() {}
00097   virtual const char* what() const throw();
00098 };
00099 
00104 class BaseExport FileException : public Exception
00105 {
00106 public:
00108   FileException(const char * sMessage, const char * sFileName=0);
00110   FileException(const char * sMessage, const FileInfo& File);
00112   FileException();
00114   FileException(const FileException &inst);
00116   virtual ~FileException() throw() {}
00118   virtual const char* what() const throw();
00119 protected:
00120   FileInfo file;
00121 };
00122 
00127 #if defined (__GNUC__)
00128 // It seems that the calling instance of our new handler expects a bad_alloc exception
00129 class BaseExport MemoryException : public Exception, virtual public std::bad_alloc
00130 #else
00131 class BaseExport MemoryException : public Exception
00132 #endif
00133 {
00134 public:
00136   MemoryException();
00138   MemoryException(const MemoryException &inst);
00140   virtual ~MemoryException() throw() {}
00141 #if defined (__GNUC__)
00143   virtual const char* what() const throw();
00144 #endif
00145 };
00146 
00151 class BaseExport AccessViolation : public Exception
00152 {
00153 public:
00155   AccessViolation();
00157   AccessViolation(const AccessViolation &inst);
00159   virtual ~AccessViolation() throw() {}
00160 };
00161 
00166 class BaseExport AbnormalProgramTermination : public Exception
00167 {
00168 public:
00170   AbnormalProgramTermination();
00172   AbnormalProgramTermination(const AbnormalProgramTermination &inst);
00174   virtual ~AbnormalProgramTermination() throw() {}
00175 };
00176 
00177 
00178 inline void Exception::setMessage(const char * sMessage)
00179 {
00180   _sErrMsg = sMessage;
00181 }
00182 
00183 inline void Exception::setMessage(const std::string& sMessage)
00184 {
00185   _sErrMsg = sMessage;
00186 }
00187 
00188 #if defined(__GNUC__) && defined (FC_OS_LINUX)
00189 class SignalException
00190 {
00191 public:
00192     SignalException();
00193     ~SignalException();
00194 
00195 private:
00196     static void throw_signal(int signum);
00197 
00198 private:
00199     struct sigaction new_action, old_action;
00200     bool ok;
00201 };
00202 #endif
00203 
00204 } //namespace Base
00205 
00206 #endif // BASE_EXCEPTION_H
00207 

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