ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkExceptionObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMacro_h
19 #error "Do not include itkExceptionObject.h directly, include itkMacro.h instead."
20 #else // __itkMacro.h
21 
22 #ifndef __itkExceptionObject_h
23 #define __itkExceptionObject_h
24 
25 #include <string>
26 #include <stdexcept>
27 
28 #include "itkSmartPointer.h"
29 
30 namespace itk
31 {
51 class ITKCommon_EXPORT ExceptionObject:public std::exception
52 {
53 public:
54  typedef std::exception Superclass;
59  explicit ExceptionObject(const char *file, unsigned int lineNumber = 0,
60  const char *desc = "None", const char *loc = "Unknown");
61  explicit ExceptionObject(const std::string & file, unsigned int lineNumber = 0,
62  const std::string & desc = "None",
63  const std::string & loc = "Unknown");
64  ExceptionObject(const ExceptionObject & orig);
66 
68  virtual ~ExceptionObject()
69  throw( );
70 
72  ExceptionObject & operator=(const ExceptionObject & orig);
73 
75  virtual bool operator==(const ExceptionObject & orig);
76 
77  virtual const char * GetNameOfClass() const
78  { return "ExceptionObject"; }
79 
84  virtual void Print(std::ostream & os) const;
85 
89  virtual void SetLocation(const std::string & s);
90 
91  virtual void SetDescription(const std::string & s);
92 
93  virtual void SetLocation(const char *s);
94 
95  virtual void SetDescription(const char *s);
96 
97  virtual const char * GetLocation() const;
98 
99  virtual const char * GetDescription() const;
100 
102  virtual const char * GetFile() const;
103 
105  virtual unsigned int GetLine() const;
106 
108  virtual const char * what() const
109  throw( );
110 
111 private:
138  {
139 public:
140  virtual void Register() const = 0;
141 
142  virtual void UnRegister() const = 0;
143 
146  };
147  class ExceptionData;
148  class ReferenceCountedExceptionData;
150  const ExceptionData * GetExceptionData() const;
151 };
152 
154 inline std::ostream & operator<<(std::ostream & os, ExceptionObject & e)
155 {
156  ( &e )->Print(os);
157  return os;
158 }
160 
171 {
172 public:
176 
178  MemoryAllocationError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
179 
181  MemoryAllocationError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
182 
184  MemoryAllocationError(const std::string & file,
185  unsigned int lineNumber,
186  const std::string & desc,
187  const std::string & loc):ExceptionObject(file, lineNumber, desc, loc) {}
188 
191  throw( ) {}
192 
193  virtual const char * GetNameOfClass() const
194  { return "MemoryAllocationError"; }
195 };
196 
203 {
204 public:
208 
210  RangeError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
211 
213  RangeError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
214 
216  virtual ~RangeError()
217  throw( ) {}
218 
219  virtual const char * GetNameOfClass() const
220  { return "RangeError"; }
221 };
222 
230 {
231 public:
237 
241  InvalidArgumentError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
242 
246  InvalidArgumentError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
247 
250  throw( ) {}
251 
252  virtual const char * GetNameOfClass() const
253  { return "InvalidArgumentError"; }
254 };
255 
262 {
263 public:
267 
269  IncompatibleOperandsError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
270 
272  IncompatibleOperandsError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
273 
276  throw( ) {}
277 
278  virtual const char * GetNameOfClass() const
279  { return "IncompatibleOperandsError"; }
280 };
281 
288 {
289 public:
293  {
294  this->SetDescription("Filter execution was aborted by an external request");
295  }
296 
298  ProcessAborted(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
299  {
300  this->SetDescription("Filter execution was aborted by an external request");
301  }
302 
304  ProcessAborted(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
305  {
306  this->SetDescription("Filter execution was aborted by an external request");
307  }
308 
310  virtual ~ProcessAborted()
311  throw( ) {}
312 
313  virtual const char * GetNameOfClass() const
314  { return "ProcessAborted"; }
315 };
316 } // end namespace itk
317 
318 #endif //__itkExceptionObject_h
319 
320 #endif //__itkMacro_h
321