Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkExceptionObject.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkExceptionObject.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/01/20 14:58:25 $
00007   Version:   $Revision: 1.27 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkExceptionObject_h
00018 #define __itkExceptionObject_h
00019 
00020 #include <string>
00021 #include <stdexcept>
00022 
00023 #include "itkWin32Header.h"
00024 
00025 
00026 namespace itk
00027 {
00028 
00047 class ITK_EXPORT ExceptionObject : public std::exception
00048 {
00049 public:
00050   typedef std::exception Superclass;
00053   ExceptionObject(const char *file="Unknown", unsigned int lineNumber=0,
00054                   const char *desc="None", const char *loc="Unknown")
00055   {
00056     m_Location = loc;
00057     m_Description = desc;
00058     m_File = file;
00059     m_Line = lineNumber;
00060   };
00061   ExceptionObject(const std::string& file, unsigned int lineNumber,
00062                   const std::string& desc="None",
00063                   const std::string& loc="Unknown")
00064   {
00065     m_Location = loc;
00066     m_Description = desc;
00067     m_File = file;
00068     m_Line = lineNumber;
00069   };
00070   ExceptionObject( const ExceptionObject &orig ): Superclass()
00071   {
00072     m_Location    = orig.m_Location;
00073     m_Description = orig.m_Description;
00074     m_File = orig.m_File;
00075     m_Line = orig.m_Line;
00076   }
00077   
00079   virtual ~ExceptionObject() throw() {}
00080 
00082   ExceptionObject &operator= ( const ExceptionObject &orig )
00083   {
00084     m_Location    = orig.m_Location;
00085     m_Description = orig.m_Description;
00086     m_File = orig.m_File;
00087     m_Line = orig.m_Line;
00088     return *this;
00089   }
00090   
00092   virtual bool operator==( const ExceptionObject &orig )
00093   {
00094     if ( m_Location    == orig.m_Location &&
00095          m_Description == orig.m_Description &&
00096          m_File == orig.m_File &&
00097          m_Line == orig.m_Line) 
00098       {
00099       return true;
00100       }
00101     else 
00102       {
00103       return false;
00104       }
00105   }
00106           
00107   virtual const char *GetNameOfClass() const 
00108     {return "ExceptionObject";}
00109 
00114   virtual void Print(std::ostream& os) const;
00115 
00119   virtual void SetLocation(const std::string& s)    
00120     { m_Location = s;    }
00121   virtual void SetDescription(const std::string& s) 
00122     { m_Description = s; }
00123   virtual void SetLocation(const char * s)          
00124     { m_Location = s;    }
00125   virtual void SetDescription (const char *s)       
00126     { m_Description = s; }
00127   virtual const char *GetLocation()    const 
00128     { return m_Location.c_str();    }
00129   virtual const char *GetDescription() const 
00130     { return m_Description.c_str(); }
00131   
00133   virtual const char *GetFile()    const 
00134     { return m_File.c_str(); }
00135 
00137   virtual unsigned int GetLine() const 
00138     { return m_Line; }
00139   
00141   virtual const char* what() const throw()
00142     { return m_Description.c_str(); }
00143   
00144 private:
00146   std::string  m_Location;
00147   std::string  m_Description;
00148   std::string  m_File;
00149   unsigned int m_Line;
00150  
00151 };
00152 
00154 inline std::ostream& operator<<(std::ostream& os, ExceptionObject &e)
00155 {
00156   (&e)->Print(os);
00157   return os;
00158 }
00159 
00168 class RangeError : public ExceptionObject
00169 {
00170 public:
00173   RangeError() : ExceptionObject() {}
00174   
00176   RangeError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00177 
00179   RangeError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00180 
00182   virtual ~RangeError() throw() {}
00183 
00184   virtual const char *GetNameOfClass() const 
00185     {return "RangeError";}
00186 
00187 };
00188 
00194 class InvalidArgumentError : public ExceptionObject
00195 {
00196 public:
00201   InvalidArgumentError() : ExceptionObject() {}
00202   
00206   InvalidArgumentError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00207 
00211   InvalidArgumentError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00212 
00214   virtual ~InvalidArgumentError() throw() {}
00215 
00216   virtual const char *GetNameOfClass() const 
00217     {return "InvalidArgumentError";}
00218 };
00219 
00224 class IncompatibleOperandsError : public ExceptionObject
00225 {
00226 public:
00229   IncompatibleOperandsError() : ExceptionObject() {}
00230   
00232   IncompatibleOperandsError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00233 
00235   IncompatibleOperandsError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00236 
00238   virtual ~IncompatibleOperandsError() throw() {}
00239 
00240   virtual const char *GetNameOfClass() const 
00241     {return "IncompatibleOperandsError";}
00242 };
00243 
00244 
00245 } // end namespace itk
00246 
00247 #endif
00248 

Generated at Fri May 21 01:14:40 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000