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 RangeError :
public ExceptionObject
00189 {
00190
public:
00193 RangeError() : ExceptionObject() {}
00194
00196 RangeError(
const char *file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00197
00199 RangeError(
const std::string& file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00200
00202
virtual ~RangeError() throw() {}
00203
00204
virtual const char *GetNameOfClass()
const
00205
{
return "RangeError";}
00206
00207 };
00208
00214
class InvalidArgumentError :
public ExceptionObject
00215 {
00216
public:
00221 InvalidArgumentError() : ExceptionObject() {}
00222
00226 InvalidArgumentError(
const char *file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00227
00231 InvalidArgumentError(
const std::string& file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00232
00234
virtual ~InvalidArgumentError() throw() {}
00235
00236
virtual const char *GetNameOfClass()
const
00237
{
return "InvalidArgumentError";}
00238 };
00239
00244
class IncompatibleOperandsError :
public ExceptionObject
00245 {
00246
public:
00249 IncompatibleOperandsError() : ExceptionObject() {}
00250
00252 IncompatibleOperandsError(
const char *file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00253
00255 IncompatibleOperandsError(
const std::string& file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {}
00256
00258
virtual ~IncompatibleOperandsError() throw() {}
00259
00260
virtual const char *GetNameOfClass()
const
00261
{
return "IncompatibleOperandsError";}
00262 };
00263
00268
class ProcessAborted :
public ExceptionObject
00269 {
00270
public:
00273 ProcessAborted() : ExceptionObject() {
00274 this->SetDescription(
"Filter execution was aborted by an external request"); }
00275
00277 ProcessAborted(
const char *file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {
00278 this->SetDescription(
"Filter execution was aborted by an external request"); }
00279
00281 ProcessAborted(
const std::string& file,
unsigned int lineNumber) : ExceptionObject(file, lineNumber) {
00282 this->SetDescription(
"Filter execution was aborted by an external request"); }
00283
00285
virtual ~ProcessAborted() throw() {}
00286
00287
virtual const char *GetNameOfClass()
const
00288
{
return "ProcessAborted";}
00289
00290 };
00291
00292
00293 }
00294
00295
#endif
00296
00297
#endif