ITK  4.13.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() ITK_NOEXCEPT ITK_OVERRIDE;
69 
71  ExceptionObject & operator=(const ExceptionObject & orig);
72 
74  virtual bool operator==(const ExceptionObject & orig);
75 
76  virtual const char * GetNameOfClass() const
77  { return "ExceptionObject"; }
78 
83  virtual void Print(std::ostream & os) const;
84 
88  virtual void SetLocation(const std::string & s);
89 
90  virtual void SetDescription(const std::string & s);
91 
92  virtual void SetLocation(const char *s);
93 
94  virtual void SetDescription(const char *s);
95 
96  virtual const char * GetLocation() const;
97 
98  virtual const char * GetDescription() const;
99 
101  virtual const char * GetFile() const;
102 
104  virtual unsigned int GetLine() const;
105 
107  virtual const char * what() const ITK_NOEXCEPT ITK_OVERRIDE;
108 
109 private:
136  {
137 public:
138  virtual void Register() const = 0;
139 
140  virtual void UnRegister() const = 0;
141 
142  ReferenceCounterInterface();
143  virtual ~ReferenceCounterInterface();
144  };
145  class ExceptionData;
146  class ReferenceCountedExceptionData;
148  const ExceptionData * GetExceptionData() const;
149 };
150 
152 inline std::ostream & operator<<(std::ostream & os, ExceptionObject & e)
153 {
154  ( &e )->Print(os);
155  return os;
156 }
158 
168 class ITKCommon_EXPORT MemoryAllocationError:public ExceptionObject
169 {
170 public:
174 
176  MemoryAllocationError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
177 
179  MemoryAllocationError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
180 
182  MemoryAllocationError(const std::string & file,
183  unsigned int lineNumber,
184  const std::string & desc,
185  const std::string & loc):ExceptionObject(file, lineNumber, desc, loc) {}
186 
188  virtual ~MemoryAllocationError() ITK_NOEXCEPT ITK_OVERRIDE;
189 
190  virtual const char * GetNameOfClass() const ITK_OVERRIDE
191  { return "MemoryAllocationError"; }
192 };
193 
199 class ITKCommon_EXPORT RangeError:public ExceptionObject
200 {
201 public:
205 
207  RangeError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
208 
210  RangeError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
211 
213  virtual ~RangeError() ITK_NOEXCEPT ITK_OVERRIDE;
214 
215  virtual const char * GetNameOfClass() const ITK_OVERRIDE
216  { return "RangeError"; }
217 };
218 
225 class ITKCommon_EXPORT InvalidArgumentError:public ExceptionObject
226 {
227 public:
233 
237  InvalidArgumentError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
238 
242  InvalidArgumentError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
243 
245  virtual ~InvalidArgumentError() ITK_NOEXCEPT ITK_OVERRIDE;
246 
247  virtual const char * GetNameOfClass() const ITK_OVERRIDE
248  { return "InvalidArgumentError"; }
249 };
250 
256 class ITKCommon_EXPORT IncompatibleOperandsError:public ExceptionObject
257 {
258 public:
262 
264  IncompatibleOperandsError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
265 
267  IncompatibleOperandsError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
268 
270  virtual ~IncompatibleOperandsError() ITK_NOEXCEPT ITK_OVERRIDE;
271 
272  virtual const char * GetNameOfClass() const ITK_OVERRIDE
273  { return "IncompatibleOperandsError"; }
274 };
275 
281 class ITKCommon_EXPORT ProcessAborted:public ExceptionObject
282 {
283 public:
287  {
288  this->SetDescription("Filter execution was aborted by an external request");
289  }
290 
292  ProcessAborted(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
293  {
294  this->SetDescription("Filter execution was aborted by an external request");
295  }
296 
298  ProcessAborted(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
299  {
300  this->SetDescription("Filter execution was aborted by an external request");
301  }
302 
304  virtual ~ProcessAborted() ITK_NOEXCEPT ITK_OVERRIDE;
305 
306  virtual const char * GetNameOfClass() const ITK_OVERRIDE
307  { return "ProcessAborted"; }
308 };
309 } // end namespace itk
310 
311 #endif //itkExceptionObject_h
312 
313 #endif //itkMacro_h
ProcessAborted(const std::string &file, unsigned int lineNumber)
InvalidArgumentError(const char *file, unsigned int lineNumber)
IncompatibleOperandsError(const char *file, unsigned int lineNumber)
RangeError(const std::string &file, unsigned int lineNumber)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:192
ProcessAborted(const char *file, unsigned int lineNumber)
Standard exception handling object.
SmartPointer< const ReferenceCounterInterface > m_ExceptionData
InvalidArgumentError(const std::string &file, unsigned int lineNumber)
MemoryAllocationError(const std::string &file, unsigned int lineNumber, const std::string &desc, const std::string &loc)
MemoryAllocationError(const std::string &file, unsigned int lineNumber)
Implements transparent reference counting.
RangeError(const char *file, unsigned int lineNumber)
IncompatibleOperandsError(const std::string &file, unsigned int lineNumber)
MemoryAllocationError(const char *file, unsigned int lineNumber)
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56
std::exception Superclass