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  itkVirtualGetNameOfClassMacro(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  itkOverrideGetNameOfClassMacro(MemoryAllocationError);
164 };
172 class ITKCommon_EXPORT RangeError : public ExceptionObject
173 {
174 public:
175  // Inherit the constructors from its base class.
176  using ExceptionObject::ExceptionObject;
177 
179  itkOverrideGetNameOfClassMacro(RangeError);
180 };
189 class ITKCommon_EXPORT InvalidArgumentError : public ExceptionObject
190 {
191 public:
192  // Inherit the constructors from its base class.
193  using ExceptionObject::ExceptionObject;
194 
196  itkOverrideGetNameOfClassMacro(InvalidArgumentError);
197 };
205 class ITKCommon_EXPORT IncompatibleOperandsError : public ExceptionObject
206 {
207 public:
208  // Inherit the constructors from its base class.
209  using ExceptionObject::ExceptionObject;
210 
212  itkOverrideGetNameOfClassMacro(IncompatibleOperandsError);
213 };
221 class ITKCommon_EXPORT ProcessAborted : public ExceptionObject
222 {
223 public:
226  ProcessAborted()
227  : ExceptionObject()
228  {
229  this->SetDescription("Filter execution was aborted by an external request");
230  }
231 
233  ProcessAborted(const char * file, unsigned int lineNumber)
234  : ExceptionObject(file, lineNumber)
235  {
236  this->SetDescription("Filter execution was aborted by an external request");
237  }
238 
240  ProcessAborted(const std::string & file, unsigned int lineNumber)
241  : ExceptionObject(file, lineNumber)
242  {
243  this->SetDescription("Filter execution was aborted by an external request");
244  }
245 
247  itkOverrideGetNameOfClassMacro(ProcessAborted);
248 };
249 } // end namespace itk
252 #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:56
Superclass
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
Definition: itkAddImageFilter.h:90