00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 }
00086
00088 virtual ~ExceptionObject() throw() {}
00089
00091 ExceptionObject &operator= ( const ExceptionObject &orig )
00092 {
00093 m_Location = orig.m_Location;
00094 m_Description = orig.m_Description;
00095 m_File = orig.m_File;
00096 m_Line = orig.m_Line;
00097 this->UpdateWhat();
00098 return *this;
00099 }
00100
00102 virtual bool operator==( const ExceptionObject &orig )
00103 {
00104 if ( m_Location == orig.m_Location &&
00105 m_Description == orig.m_Description &&
00106 m_File == orig.m_File &&
00107 m_Line == orig.m_Line)
00108 {
00109 return true;
00110 }
00111 else
00112 {
00113 return false;
00114 }
00115 }
00116
00117 virtual const char *GetNameOfClass() const
00118 {return "ExceptionObject";}
00119
00124 virtual void Print(std::ostream& os) const;
00125
00129 virtual void SetLocation(const std::string& s)
00130 { m_Location = s; this->UpdateWhat(); }
00131 virtual void SetDescription(const std::string& s)
00132 { m_Description = s; this->UpdateWhat(); }
00133 virtual void SetLocation(const char * s)
00134 { m_Location = s; this->UpdateWhat(); }
00135 virtual void SetDescription (const char *s)
00136 { m_Description = s; this->UpdateWhat(); }
00137 virtual const char *GetLocation() const
00138 { return m_Location.c_str(); }
00139 virtual const char *GetDescription() const
00140 { return m_Description.c_str(); }
00141
00143 virtual const char *GetFile() const
00144 { return m_File.c_str(); }
00145
00147 virtual unsigned int GetLine() const
00148 { return m_Line; }
00149
00151 virtual const char* what() const throw()
00152 { return m_What.c_str(); }
00153
00154 protected:
00155 void UpdateWhat()
00156 {
00157 OStringStream loc;
00158 loc << ":" << m_Line << ":\n";
00159 m_What = m_File;
00160 m_What += loc.str();
00161 m_What += m_Description;
00162 }
00163 private:
00165 std::string m_Location;
00166 std::string m_Description;
00167 std::string m_What;
00168 std::string m_File;
00169 unsigned int m_Line;
00170
00171 };
00172
00174 inline std::ostream& operator<<(std::ostream& os, ExceptionObject &e)
00175 {
00176 (&e)->Print(os);
00177 return os;
00178 }
00179
00188 class MemoryAllocationError : public ExceptionObject
00189 {
00190 public:
00193 MemoryAllocationError() : ExceptionObject() {}
00194
00196 MemoryAllocationError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00197
00199 MemoryAllocationError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00200
00202 MemoryAllocationError(const std::string& file, unsigned int lineNumber, const std::string& desc, const std::string& loc) : ExceptionObject(file, lineNumber, desc, loc) {}
00203
00205 virtual ~MemoryAllocationError() throw() {}
00206
00207 virtual const char* GetNameOfClass() const
00208 { return "MemoryAllocationError"; }
00209 };
00210
00215 class RangeError : public ExceptionObject
00216 {
00217 public:
00220 RangeError() : ExceptionObject() {}
00221
00223 RangeError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00224
00226 RangeError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00227
00229 virtual ~RangeError() throw() {}
00230
00231 virtual const char *GetNameOfClass() const
00232 {return "RangeError";}
00233
00234 };
00235
00241 class InvalidArgumentError : public ExceptionObject
00242 {
00243 public:
00248 InvalidArgumentError() : ExceptionObject() {}
00249
00253 InvalidArgumentError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00254
00258 InvalidArgumentError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00259
00261 virtual ~InvalidArgumentError() throw() {}
00262
00263 virtual const char *GetNameOfClass() const
00264 {return "InvalidArgumentError";}
00265 };
00266
00271 class IncompatibleOperandsError : public ExceptionObject
00272 {
00273 public:
00276 IncompatibleOperandsError() : ExceptionObject() {}
00277
00279 IncompatibleOperandsError(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00280
00282 IncompatibleOperandsError(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00283
00285 virtual ~IncompatibleOperandsError() throw() {}
00286
00287 virtual const char *GetNameOfClass() const
00288 {return "IncompatibleOperandsError";}
00289 };
00290
00295 class ProcessAborted : public ExceptionObject
00296 {
00297 public:
00300 ProcessAborted() : ExceptionObject() {
00301 this->SetDescription("Filter execution was aborted by an external request"); }
00302
00304 ProcessAborted(const char *file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {
00305 this->SetDescription("Filter execution was aborted by an external request"); }
00306
00308 ProcessAborted(const std::string& file, unsigned int lineNumber) : ExceptionObject(file, lineNumber) {
00309 this->SetDescription("Filter execution was aborted by an external request"); }
00310
00312 virtual ~ProcessAborted() throw() {}
00313
00314 virtual const char *GetNameOfClass() const
00315 {return "ProcessAborted";}
00316
00317 };
00318
00319
00320 }
00321
00322 #endif
00323
00324 #endif