ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkExceptionObject.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMacro_h
00019 #error "Do not include itkExceptionObject.h directly,  include itkMacro.h instead."
00020 #else // __itkMacro.h
00021 
00022 #ifndef __itkExceptionObject_h
00023 #define __itkExceptionObject_h
00024 
00025 #include <string>
00026 #include <stdexcept>
00027 
00028 #include "itkSmartPointer.h"
00029 
00030 namespace itk
00031 {
00051 class ITKCommon_EXPORT ExceptionObject:public std::exception
00052 {
00053 public:
00054   typedef std::exception Superclass;
00058   ExceptionObject();
00059   explicit ExceptionObject(const char *file, unsigned int lineNumber = 0,
00060                            const char *desc = "None", const char *loc = "Unknown");
00061   explicit ExceptionObject(const std::string & file, unsigned int lineNumber = 0,
00062                            const std::string & desc = "None",
00063                            const std::string & loc = "Unknown");
00064   ExceptionObject(const ExceptionObject & orig);
00066 
00068   virtual ~ExceptionObject()
00069   throw( );
00070 
00072   ExceptionObject & operator=(const ExceptionObject & orig);
00073 
00075   virtual bool operator==(const ExceptionObject & orig);
00076 
00077   virtual const char * GetNameOfClass() const
00078   { return "ExceptionObject"; }
00079 
00084   virtual void Print(std::ostream & os) const;
00085 
00089   virtual void SetLocation(const std::string & s);
00090 
00091   virtual void SetDescription(const std::string & s);
00092 
00093   virtual void SetLocation(const char *s);
00094 
00095   virtual void SetDescription(const char *s);
00096 
00097   virtual const char * GetLocation()    const;
00098 
00099   virtual const char * GetDescription() const;
00100 
00102   virtual const char * GetFile()    const;
00103 
00105   virtual unsigned int GetLine() const;
00106 
00108   virtual const char * what() const
00109   throw( );
00110 
00111 private:
00137   class ReferenceCounterInterface
00138   {
00139 public:
00140     virtual void Register() const = 0;
00141 
00142     virtual void UnRegister() const = 0;
00143 
00144     ReferenceCounterInterface() {}
00145     virtual ~ReferenceCounterInterface() {}
00146   };
00147   class ExceptionData;
00148   class ReferenceCountedExceptionData;
00149   SmartPointer< const ReferenceCounterInterface > m_ExceptionData;
00150   const ExceptionData * GetExceptionData() const;
00151 };
00152 
00154 inline std::ostream & operator<<(std::ostream & os, ExceptionObject & e)
00155 {
00156   ( &e )->Print(os);
00157   return os;
00158 }
00160 
00170 class MemoryAllocationError:public ExceptionObject
00171 {
00172 public:
00175   MemoryAllocationError():ExceptionObject() {}
00176 
00178   MemoryAllocationError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00179 
00181   MemoryAllocationError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00182 
00184   MemoryAllocationError(const std::string & file,
00185                         unsigned int lineNumber,
00186                         const std::string & desc,
00187                         const std::string & loc):ExceptionObject(file, lineNumber, desc, loc) {}
00188 
00190   virtual ~MemoryAllocationError()
00191   throw( ) {}
00192 
00193   virtual const char * GetNameOfClass() const
00194   { return "MemoryAllocationError"; }
00195 };
00196 
00202 class RangeError:public ExceptionObject
00203 {
00204 public:
00207   RangeError():ExceptionObject() {}
00208 
00210   RangeError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00211 
00213   RangeError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00214 
00216   virtual ~RangeError()
00217   throw( ) {}
00218 
00219   virtual const char * GetNameOfClass() const
00220   { return "RangeError"; }
00221 };
00222 
00229 class InvalidArgumentError:public ExceptionObject
00230 {
00231 public:
00236   InvalidArgumentError():ExceptionObject() {}
00237 
00241   InvalidArgumentError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00242 
00246   InvalidArgumentError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00247 
00249   virtual ~InvalidArgumentError()
00250   throw( ) {}
00251 
00252   virtual const char * GetNameOfClass() const
00253   { return "InvalidArgumentError"; }
00254 };
00255 
00261 class IncompatibleOperandsError:public ExceptionObject
00262 {
00263 public:
00266   IncompatibleOperandsError():ExceptionObject() {}
00267 
00269   IncompatibleOperandsError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00270 
00272   IncompatibleOperandsError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
00273 
00275   virtual ~IncompatibleOperandsError()
00276   throw( ) {}
00277 
00278   virtual const char * GetNameOfClass() const
00279   { return "IncompatibleOperandsError"; }
00280 };
00281 
00287 class ProcessAborted:public ExceptionObject
00288 {
00289 public:
00292   ProcessAborted():ExceptionObject()
00293   {
00294     this->SetDescription("Filter execution was aborted by an external request");
00295   }
00296 
00298   ProcessAborted(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
00299   {
00300     this->SetDescription("Filter execution was aborted by an external request");
00301   }
00302 
00304   ProcessAborted(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
00305   {
00306     this->SetDescription("Filter execution was aborted by an external request");
00307   }
00308 
00310   virtual ~ProcessAborted()
00311   throw( ) {}
00312 
00313   virtual const char * GetNameOfClass() const
00314   { return "ProcessAborted"; }
00315 };
00316 } // end namespace itk
00317 
00318 #endif //__itkExceptionObject_h
00319 
00320 #endif //__itkMacro_h
00321