00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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:
00052 ExceptionObject(const char *file="Unknown", unsigned int lineNumber=0,
00053 const char *desc="None", const char *loc="Unknown")
00054 {
00055 m_Location = loc;
00056 m_Description = desc;
00057 m_File = file;
00058 m_Line = lineNumber;
00059 };
00060 ExceptionObject(const std::string& file, unsigned int lineNumber,
00061 const std::string& desc="None",
00062 const std::string& loc="Unknown")
00063 {
00064 m_Location = loc;
00065 m_Description = desc;
00066 m_File = file;
00067 m_Line = lineNumber;
00068 };
00069 ExceptionObject( const ExceptionObject &orig )
00070 {
00071 m_Location = orig.m_Location;
00072 m_Description = orig.m_Description;
00073 m_File = orig.m_File;
00074 m_Line = orig.m_Line;
00075 }
00076
00078 virtual ~ExceptionObject() throw() {}
00079
00081 ExceptionObject &operator= ( const ExceptionObject &orig )
00082 {
00083 m_Location = orig.m_Location;
00084 m_Description = orig.m_Description;
00085 m_File = orig.m_File;
00086 m_Line = orig.m_Line;
00087 return *this;
00088 }
00089
00091 virtual bool operator==( const ExceptionObject &orig )
00092 {
00093 if ( m_Location == orig.m_Location &&
00094 m_Description == orig.m_Description &&
00095 m_File == orig.m_File &&
00096 m_Line == orig.m_Line)
00097 {
00098 return true;
00099 }
00100 else
00101 {
00102 return false;
00103 }
00104 }
00105
00106 virtual const char *GetNameOfClass() const
00107 {return "ExceptionObject";}
00108
00113 virtual void Print(std::ostream& os) const;
00114
00118 virtual void SetLocation(const std::string& s)
00119 { m_Location = s; }
00120 virtual void SetDescription(const std::string& s)
00121 { m_Description = s; }
00122 virtual void SetLocation(const char * s)
00123 { m_Location = s; }
00124 virtual void SetDescription (const char *s)
00125 { m_Description = s; }
00126 virtual const char *GetLocation() const
00127 { return m_Location.c_str(); }
00128 virtual const char *GetDescription() const
00129 { return m_Description.c_str(); }
00130
00132 virtual const char *GetFile() const
00133 { return m_File.c_str(); }
00134
00136 virtual unsigned int GetLine() const
00137 { return m_Line; }
00138
00140 virtual const char* what() const throw()
00141 { return m_Description.c_str(); }
00142
00143 private:
00145 std::string m_Location;
00146 std::string m_Description;
00147 std::string m_File;
00148 unsigned int m_Line;
00149
00150 };
00151
00153 inline std::ostream& operator<<(std::ostream& os, ExceptionObject &e)
00154 {
00155 (&e)->Print(os);
00156 return os;
00157 }
00158
00167 class RangeError : public ExceptionObject
00168 {
00169 public:
00172 RangeError() : ExceptionObject() {}
00173
00175 RangeError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00176
00178 RangeError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00179
00181 virtual ~RangeError() throw() {}
00182
00183 virtual const char *GetNameOfClass() const
00184 {return "RangeError";}
00185
00186 };
00187
00193 class InvalidArgumentError : public ExceptionObject
00194 {
00195 public:
00200 InvalidArgumentError() : ExceptionObject() {}
00201
00205 InvalidArgumentError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00206
00210 InvalidArgumentError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00211
00213 virtual ~InvalidArgumentError() throw() {}
00214
00215 virtual const char *GetNameOfClass() const
00216 {return "InvalidArgumentError";}
00217 };
00218
00223 class IncompatibleOperandsError : public ExceptionObject
00224 {
00225 public:
00228 IncompatibleOperandsError() : ExceptionObject() {}
00229
00231 IncompatibleOperandsError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00232
00234 IncompatibleOperandsError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00235
00237 virtual ~IncompatibleOperandsError() throw() {}
00238
00239 virtual const char *GetNameOfClass() const
00240 {return "IncompatibleOperandsError";}
00241 };
00242
00243
00244 }
00245
00246 #endif
00247