ITK  5.1.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 itkExceptionObject_h
19 #error "Do not include itkExceptionObject.h directly, include itkMacro.h instead."
20 #else // itkExceptionObject_h
21 
22 #include <string>
23 #include <stdexcept>
24 
25 #include "itkSmartPointer.h"
26 
27 namespace itk
28 {
48 class ITKCommon_EXPORT ExceptionObject:public std::exception
49 {
50 public:
51  using Superclass = std::exception;
55  ExceptionObject() noexcept;
56  explicit ExceptionObject(const char *file, unsigned int lineNumber = 0,
57  const char *desc = "None", const char *loc = "Unknown");
58  explicit ExceptionObject(const std::string & file, unsigned int lineNumber = 0,
59  const std::string & desc = "None",
60  const std::string & loc = "Unknown");
61  ExceptionObject(const ExceptionObject & orig) noexcept;
63 
65  ~ExceptionObject() noexcept override;
66 
68  ExceptionObject & operator=(const ExceptionObject & orig) noexcept;
69 
71  virtual bool operator==(const ExceptionObject & orig);
72 
73  virtual const char * GetNameOfClass() const
74  { return "ExceptionObject"; }
75 
80  virtual void Print(std::ostream & os) const;
81 
85  virtual void SetLocation(const std::string & s);
86 
87  virtual void SetDescription(const std::string & s);
88 
89  virtual void SetLocation(const char *s);
90 
91  virtual void SetDescription(const char *s);
92 
93  virtual const char * GetLocation() const;
94 
95  virtual const char * GetDescription() const;
96 
98  virtual const char * GetFile() const;
99 
101  virtual unsigned int GetLine() const;
102 
104  const char * what() const noexcept override;
105 
106 private:
132  class ReferenceCounterInterface
133  {
134 public:
135  virtual void Register() const = 0;
136 
137  virtual void UnRegister() const = 0;
138 
139  ReferenceCounterInterface();
140  virtual ~ReferenceCounterInterface();
141  };
142  class ExceptionData;
143  class ReferenceCountedExceptionData;
144  SmartPointer< const ReferenceCounterInterface > m_ExceptionData;
145  const ExceptionData * GetExceptionData() const;
146 };
147 
149 inline std::ostream & operator<<(std::ostream & os, ExceptionObject & e)
150 {
151  ( &e )->Print(os);
152  return os;
153 }
155 
165 class ITKCommon_EXPORT MemoryAllocationError:public ExceptionObject
166 {
167 public:
170  MemoryAllocationError() noexcept:ExceptionObject() {}
171 
173  MemoryAllocationError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
174 
176  MemoryAllocationError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
177 
179  MemoryAllocationError(const std::string & file,
180  unsigned int lineNumber,
181  const std::string & desc,
182  const std::string & loc):ExceptionObject(file, lineNumber, desc, loc) {}
183 
185  ~MemoryAllocationError() noexcept override;
186 
187  const char * GetNameOfClass() const override
188  { return "MemoryAllocationError"; }
189 };
190 
196 class ITKCommon_EXPORT RangeError:public ExceptionObject
197 {
198 public:
201  RangeError() noexcept:ExceptionObject() {}
202 
204  RangeError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
205 
207  RangeError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
208 
210  ~RangeError() noexcept override;
211 
212  const char * GetNameOfClass() const override
213  { return "RangeError"; }
214 };
215 
222 class ITKCommon_EXPORT InvalidArgumentError:public ExceptionObject
223 {
224 public:
229  InvalidArgumentError() noexcept:ExceptionObject() {}
230 
234  InvalidArgumentError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
235 
239  InvalidArgumentError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
240 
242  ~InvalidArgumentError() noexcept override;
243 
244  const char * GetNameOfClass() const override
245  { return "InvalidArgumentError"; }
246 };
247 
253 class ITKCommon_EXPORT IncompatibleOperandsError:public ExceptionObject
254 {
255 public:
258  IncompatibleOperandsError() noexcept:ExceptionObject() {}
259 
261  IncompatibleOperandsError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
262 
264  IncompatibleOperandsError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
265 
267  ~IncompatibleOperandsError() noexcept override;
268 
269  const char * GetNameOfClass() const override
270  { return "IncompatibleOperandsError"; }
271 };
272 
278 class ITKCommon_EXPORT ProcessAborted:public ExceptionObject
279 {
280 public:
283  ProcessAborted():ExceptionObject()
284  {
285  this->SetDescription("Filter execution was aborted by an external request");
286  }
287 
289  ProcessAborted(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
290  {
291  this->SetDescription("Filter execution was aborted by an external request");
292  }
293 
295  ProcessAborted(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
296  {
297  this->SetDescription("Filter execution was aborted by an external request");
298  }
299 
301  ~ProcessAborted() noexcept override;
302 
303  const char * GetNameOfClass() const override
304  { return "ProcessAborted"; }
305 };
306 } // end namespace itk
307 
308 #endif //itkExceptionObject_h
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:188
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
static constexpr double e
The base of the natural logarithm or Euler's number
Definition: itkMath.h:53