ITK  5.4.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  * https://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 "itkMacro.h"
23 
24 # include <memory> // For shared_ptr.
25 # include <string>
26 # include <stdexcept>
27 
28 namespace itk
29 {
49 class ITKCommon_EXPORT ExceptionObject : public std::exception
50 {
51 public:
52  static constexpr const char * const default_exception_message = "Generic ExceptionObject";
53  using Superclass = std::exception;
54 
56  ExceptionObject() noexcept = default;
57 
58  explicit ExceptionObject(const char * file,
59  unsigned int lineNumber = 0,
60  const char * desc = "None",
61  const char * loc = "Unknown");
62  explicit ExceptionObject(std::string file,
63  unsigned int lineNumber = 0,
64  std::string desc = "None",
65  std::string loc = "Unknown");
66 
68  ExceptionObject(const ExceptionObject &) noexcept = default;
69 
71  ExceptionObject(ExceptionObject &&) noexcept = default;
72 
74  ExceptionObject &
75  operator=(const ExceptionObject &) noexcept = default;
76 
78  ExceptionObject &
79  operator=(ExceptionObject &&) noexcept = default;
80 
83  ~ExceptionObject() override;
84 
86  virtual bool
87  operator==(const ExceptionObject & orig) const;
88 
90  itkTypeMacroNoParent(ExceptionObject);
91 
96  virtual void
97  Print(std::ostream & os) const;
98 
102  virtual void
103  SetLocation(const std::string & s);
104 
105  virtual void
106  SetDescription(const std::string & s);
107 
108  virtual void
109  SetLocation(const char * s);
110 
111  virtual void
112  SetDescription(const char * s);
113 
114  virtual const char *
115  GetLocation() const;
116 
117  virtual const char *
118  GetDescription() const;
119 
121  virtual const char *
122  GetFile() const;
123 
125  virtual unsigned int
126  GetLine() const;
127 
129  const char *
130  what() const noexcept override;
131 
132 private:
133  class ExceptionData;
134 
135  std::shared_ptr<const ExceptionData> m_ExceptionData{};
136 };
137 
139 inline std::ostream &
140 operator<<(std::ostream & os, const ExceptionObject & e)
141 {
142  e.Print(os);
143  return os;
144 }
156 class ITKCommon_EXPORT MemoryAllocationError : public ExceptionObject
157 {
158 public:
159  // Inherit the constructors from its base class.
160  using ExceptionObject::ExceptionObject;
161 
163  itkTypeMacro(MemoryAllocationError, ExceptionObject);
164 };
165 
171 class ITKCommon_EXPORT RangeError : public ExceptionObject
172 {
173 public:
174  // Inherit the constructors from its base class.
175  using ExceptionObject::ExceptionObject;
176 
178  itkTypeMacro(RangeError, ExceptionObject);
179 };
180 
187 class ITKCommon_EXPORT InvalidArgumentError : public ExceptionObject
188 {
189 public:
190  // Inherit the constructors from its base class.
191  using ExceptionObject::ExceptionObject;
192 
194  itkTypeMacro(InvalidArgumentError, ExceptionObject);
195 };
196 
202 class ITKCommon_EXPORT IncompatibleOperandsError : public ExceptionObject
203 {
204 public:
205  // Inherit the constructors from its base class.
206  using ExceptionObject::ExceptionObject;
207 
209  itkTypeMacro(IncompatibleOperandsError, ExceptionObject);
210 };
211 
217 class ITKCommon_EXPORT ProcessAborted : public ExceptionObject
218 {
219 public:
222  ProcessAborted()
223  : ExceptionObject()
224  {
225  this->SetDescription("Filter execution was aborted by an external request");
226  }
227 
229  ProcessAborted(const char * file, unsigned int lineNumber)
230  : ExceptionObject(file, lineNumber)
231  {
232  this->SetDescription("Filter execution was aborted by an external request");
233  }
234 
236  ProcessAborted(const std::string & file, unsigned int lineNumber)
237  : ExceptionObject(file, lineNumber)
238  {
239  this->SetDescription("Filter execution was aborted by an external request");
240  }
241 
243  itkTypeMacro(ProcessAborted, ExceptionObject);
244 };
245 } // end namespace itk
246 
247 #endif // itkExceptionObject_h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itkMacro.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:55
Superclass
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
Definition: itkAddImageFilter.h:89