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: 2006-01-02 17:14:05 $
00007   Version:   $Revision: 1.36 $
00008 
00009   Copyright (c) Insight Software 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 // itkExceptionObject.h is normally included through itkMacro.h, but
00018 // some code includes it directly.
00019 #ifndef __itkMacro_h
00020 #include "itkMacro.h"
00021 #else
00022 
00023 #ifndef __itkExceptionObject_h
00024 #define __itkExceptionObject_h
00025 
00026 #include <string>
00027 #include <stdexcept>
00028 
00029 #include "itkWin32Header.h"
00030 
00031 
00032 namespace itk
00033 {
00034 
00053 class ITKCommon_EXPORT ExceptionObject : public std::exception
00054 {
00055 public:
00056   typedef std::exception Superclass;
00059   ExceptionObject(const char *file="Unknown", unsigned int lineNumber=0,
00060                   const char *desc="None", const char *loc="Unknown")
00061   {
00062     m_Location = loc;
00063     m_Description = desc;
00064     m_File = file;
00065     m_Line = lineNumber;
00066     this->UpdateWhat();
00067   };
00068   ExceptionObject(const std::string& file, unsigned int lineNumber,
00069                   const std::string& desc="None",
00070                   const std::string& loc="Unknown")
00071   {
00072     m_Location = loc;
00073     m_Description = desc;
00074     m_File = file;
00075     m_Line = lineNumber;
00076     this->UpdateWhat();
00077   };
00078   ExceptionObject( const ExceptionObject &orig ): Superclass()
00079   {
00080     m_Location    = orig.m_Location;
00081     m_Description = orig.m_Description;
00082     m_File = orig.m_File;
00083     m_Line = orig.m_Line;
00084     this->UpdateWhat();
00085   }
00087 
00089   virtual ~ExceptionObject() throw() {}
00090 
00092   ExceptionObject &operator= ( const ExceptionObject &orig )
00093   {
00094     m_Location    = orig.m_Location;
00095     m_Description = orig.m_Description;
00096     m_File = orig.m_File;
00097     m_Line = orig.m_Line;
00098     this->UpdateWhat();
00099     return *this;
00100   }
00102 
00104   virtual bool operator==( const ExceptionObject &orig )
00105   {
00106     if ( m_Location    == orig.m_Location &&
00107          m_Description == orig.m_Description &&
00108          m_File == orig.m_File &&
00109          m_Line == orig.m_Line) 
00110       {
00111       return true;
00112       }
00113     else 
00114       {
00115       return false;
00116       }
00117   }
00119 
00120   virtual const char *GetNameOfClass() const 
00121     {return "ExceptionObject";}
00122 
00127   virtual void Print(std::ostream& os) const;
00128 
00132   virtual void SetLocation(const std::string& s)    
00133     { m_Location = s; this->UpdateWhat(); }
00134   virtual void SetDescription(const std::string& s) 
00135     { m_Description = s; this->UpdateWhat(); }
00136   virtual void SetLocation(const char * s)          
00137     { m_Location = s; this->UpdateWhat(); }
00138   virtual void SetDescription (const char *s)       
00139     { m_Description = s; this->UpdateWhat(); }
00140   virtual const char *GetLocation()    const 
00141     { return m_Location.c_str();    }
00142   virtual const char *GetDescription() const 
00143     { return m_Description.c_str(); }
00145 
00147   virtual const char *GetFile()    const 
00148     { return m_File.c_str(); }
00149 
00151   virtual unsigned int GetLine() const 
00152     { return m_Line; }
00153 
00155   virtual const char* what() const throw()
00156     { return m_What.c_str(); }
00157 
00158 protected:
00159   void UpdateWhat()
00160     {
00161     OStringStream loc;
00162     loc << ":" << m_Line << ":\n";
00163     m_What = m_File;
00164     m_What += loc.str();
00165     m_What += m_Description;
00166     }
00167 private:
00169   std::string  m_Location;
00170   std::string  m_Description;
00171   std::string  m_What;
00172   std::string  m_File;
00173   unsigned int m_Line;
00174 
00175 };
00176 
00178 inline std::ostream& operator<<(std::ostream& os, ExceptionObject &e)
00179 {
00180   (&e)->Print(os);
00181   return os;
00182 }
00184 
00193 class MemoryAllocationError : public ExceptionObject
00194 {
00195 public:
00198   MemoryAllocationError() : ExceptionObject() {}
00199 
00201   MemoryAllocationError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00202 
00204   MemoryAllocationError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00205 
00207   MemoryAllocationError(const std::string& file, unsigned int lineNumber, const std::string& desc, const std::string& loc) : ExceptionObject(file, lineNumber, desc, loc) {}  
00208 
00210   virtual ~MemoryAllocationError() throw() {}
00211 
00212   virtual const char* GetNameOfClass() const
00213     { return "MemoryAllocationError"; }
00214 };
00215 
00220 class RangeError : public ExceptionObject
00221 {
00222 public:
00225   RangeError() : ExceptionObject() {}
00226 
00228   RangeError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00229 
00231   RangeError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00232 
00234   virtual ~RangeError() throw() {}
00235 
00236   virtual const char *GetNameOfClass() const 
00237     {return "RangeError";}
00238 
00239 };
00240 
00246 class InvalidArgumentError : public ExceptionObject
00247 {
00248 public:
00253   InvalidArgumentError() : ExceptionObject() {}
00254 
00258   InvalidArgumentError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00259 
00263   InvalidArgumentError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00264 
00266   virtual ~InvalidArgumentError() throw() {}
00267 
00268   virtual const char *GetNameOfClass() const 
00269     {return "InvalidArgumentError";}
00270 };
00271 
00276 class IncompatibleOperandsError : public ExceptionObject
00277 {
00278 public:
00281   IncompatibleOperandsError() : ExceptionObject() {}
00282 
00284   IncompatibleOperandsError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00285 
00287   IncompatibleOperandsError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}  
00288 
00290   virtual ~IncompatibleOperandsError() throw() {}
00291 
00292   virtual const char *GetNameOfClass() const 
00293     {return "IncompatibleOperandsError";}
00294 };
00295 
00300 class ProcessAborted : public ExceptionObject
00301 {
00302 public:
00305   ProcessAborted() : ExceptionObject() {
00306     this->SetDescription("Filter execution was aborted by an external request"); }
00307 
00309   ProcessAborted(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {
00310     this->SetDescription("Filter execution was aborted by an external request"); }
00311 
00313   ProcessAborted(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {  
00314     this->SetDescription("Filter execution was aborted by an external request"); }
00315 
00317   virtual ~ProcessAborted() throw() {}
00318 
00319   virtual const char *GetNameOfClass() const 
00320     {return "ProcessAborted";}
00321 
00322 };
00323 
00324 
00325 } // end namespace itk
00326 
00327 #endif
00328 
00329 #endif
00330 

Generated at Mon Apr 14 12:17:12 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000