ITK  5.2.0
Insight Toolkit
itkExceptionObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 <memory> // For shared_ptr.
23 # include <string>
24 # include <stdexcept>
25 
26 namespace itk
27 {
47 class ITKCommon_EXPORT ExceptionObject : public std::exception
48 {
49 public:
50  static constexpr const char * const default_exception_message = "Generic ExceptionObject";
51  using Superclass = std::exception;
52 
54  ExceptionObject() noexcept = default;
55 
56  explicit ExceptionObject(const char * file,
57  unsigned int lineNumber = 0,
58  const char * desc = "None",
59  const char * loc = "Unknown");
60  explicit ExceptionObject(std::string file,
61  unsigned int lineNumber = 0,
62  std::string desc = "None",
63  std::string loc = "Unknown");
64 
66  ExceptionObject(const ExceptionObject &) noexcept = default;
67 
69  ExceptionObject(ExceptionObject &&) noexcept = default;
70 
72  ExceptionObject &
73  operator=(const ExceptionObject &) noexcept = default;
74 
76  ExceptionObject &
77  operator=(ExceptionObject &&) noexcept = default;
78 
81  ~ExceptionObject() override;
82 
84  virtual bool
85  operator==(const ExceptionObject & orig) const;
86 
87  virtual const char *
88  GetNameOfClass() const
89  {
90  return "ExceptionObject";
91  }
92 
97  virtual void
98  Print(std::ostream & os) const;
99 
103  virtual void
104  SetLocation(const std::string & s);
105 
106  virtual void
107  SetDescription(const std::string & s);
108 
109  virtual void
110  SetLocation(const char * s);
111 
112  virtual void
113  SetDescription(const char * s);
114 
115  virtual const char *
116  GetLocation() const;
117 
118  virtual const char *
119  GetDescription() const;
120 
122  virtual const char *
123  GetFile() const;
124 
126  virtual unsigned int
127  GetLine() const;
128 
130  const char *
131  what() const noexcept override;
132 
133 private:
134  class ExceptionData;
135 
136  std::shared_ptr<const ExceptionData> m_ExceptionData;
137 };
138 
140 inline std::ostream &
141 operator<<(std::ostream & os, const ExceptionObject & e)
142 {
143  (&e)->Print(os);
144  return os;
145 }
147 
157 class ITKCommon_EXPORT MemoryAllocationError : public ExceptionObject
158 {
159 public:
160  // Inherit the constructors from its base class.
161  using ExceptionObject::ExceptionObject;
162 
163  const char *
164  GetNameOfClass() const override
165  {
166  return "MemoryAllocationError";
167  }
168 };
169 
175 class ITKCommon_EXPORT RangeError : public ExceptionObject
176 {
177 public:
178  // Inherit the constructors from its base class.
179  using ExceptionObject::ExceptionObject;
180 
181  const char *
182  GetNameOfClass() const override
183  {
184  return "RangeError";
185  }
186 };
187 
194 class ITKCommon_EXPORT InvalidArgumentError : public ExceptionObject
195 {
196 public:
197  // Inherit the constructors from its base class.
198  using ExceptionObject::ExceptionObject;
199 
200  const char *
201  GetNameOfClass() const override
202  {
203  return "InvalidArgumentError";
204  }
205 };
206 
212 class ITKCommon_EXPORT IncompatibleOperandsError : public ExceptionObject
213 {
214 public:
215  // Inherit the constructors from its base class.
216  using ExceptionObject::ExceptionObject;
217 
218  const char *
219  GetNameOfClass() const override
220  {
221  return "IncompatibleOperandsError";
222  }
223 };
224 
230 class ITKCommon_EXPORT ProcessAborted : public ExceptionObject
231 {
232 public:
235  ProcessAborted()
236  : ExceptionObject()
237  {
238  this->SetDescription("Filter execution was aborted by an external request");
239  }
240 
242  ProcessAborted(const char * file, unsigned int lineNumber)
243  : ExceptionObject(file, lineNumber)
244  {
245  this->SetDescription("Filter execution was aborted by an external request");
246  }
247 
249  ProcessAborted(const std::string & file, unsigned int lineNumber)
250  : ExceptionObject(file, lineNumber)
251  {
252  this->SetDescription("Filter execution was aborted by an external request");
253  }
254 
255  const char *
256  GetNameOfClass() const override
257  {
258  return "ProcessAborted";
259  }
260 };
261 } // end namespace itk
262 
263 #endif // itkExceptionObject_h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Math::e
static constexpr double e
Definition: itkMath.h:54