ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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#define itkExceptionObject_h
20
21// NOTE: This itkExceptionObject.h file is included by itkMacro.h, and should never be included directly.
22#ifndef allow_inclusion_of_itkExceptionObject_h
23# error "Do not include itkExceptionObject.h directly, include itkMacro.h instead."
24#endif
25
26#include <memory> // For shared_ptr.
27#include <string>
28
29namespace itk
30{
50class ITKCommon_EXPORT ExceptionObject : public std::exception
51{
52public:
53 static constexpr const char * const default_exception_message = "Generic ExceptionObject";
54 using Superclass = std::exception;
55
57 ExceptionObject() noexcept = default;
58
59 explicit ExceptionObject(std::string file,
60 unsigned int lineNumber = 0,
61 std::string description = "None",
62 std::string location = {});
63
65 ExceptionObject(const ExceptionObject &) noexcept = default;
66
68 ExceptionObject(ExceptionObject &&) noexcept = default;
69
72 operator=(const ExceptionObject &) noexcept = default;
73
76 operator=(ExceptionObject &&) noexcept = default;
77
80 ~ExceptionObject() override;
81
83 virtual bool
84 operator==(const ExceptionObject & orig) const;
85
87 itkVirtualGetNameOfClassMacro(ExceptionObject);
88
93 virtual void
94 Print(std::ostream & os) const;
95
99 virtual void
100 SetLocation(const std::string & s);
101
102 virtual void
103 SetDescription(const std::string & s);
104
105 virtual void
106 SetLocation(const char * s);
107
108 virtual void
109 SetDescription(const char * s);
110
111 virtual const char *
112 GetLocation() const;
113
114 virtual const char *
116
118 virtual const char *
119 GetFile() const;
120
122 virtual unsigned int
123 GetLine() const;
124
126 const char *
127 what() const noexcept override;
128
129private:
130 class ExceptionData;
131
132 std::shared_ptr<const ExceptionData> m_ExceptionData;
133};
134
136inline std::ostream &
137operator<<(std::ostream & os, const ExceptionObject & e)
138{
139 e.Print(os);
140 return os;
141}
142
146
152class ITKCommon_EXPORT MemoryAllocationError : public ExceptionObject
153{
154public:
155 // Inherit the constructors from its base class.
157
159 itkOverrideGetNameOfClassMacro(MemoryAllocationError);
160};
161
167class ITKCommon_EXPORT RangeError : public ExceptionObject
168{
169public:
170 // Inherit the constructors from its base class.
172
174 itkOverrideGetNameOfClassMacro(RangeError);
175};
176
183class ITKCommon_EXPORT InvalidArgumentError : public ExceptionObject
184{
185public:
186 // Inherit the constructors from its base class.
188
190 itkOverrideGetNameOfClassMacro(InvalidArgumentError);
191};
192
198class ITKCommon_EXPORT IncompatibleOperandsError : public ExceptionObject
199{
200public:
201 // Inherit the constructors from its base class.
203
205 itkOverrideGetNameOfClassMacro(IncompatibleOperandsError);
206};
207
213class ITKCommon_EXPORT ProcessAborted : public ExceptionObject
214{
215public:
220 {
221 this->SetDescription("Filter execution was aborted by an external request");
222 }
223
225 ProcessAborted(std::string file, unsigned int lineNumber)
226 : ExceptionObject(std::move(file), lineNumber, "Filter execution was aborted by an external request")
227 {}
228
230 itkOverrideGetNameOfClassMacro(ProcessAborted);
231};
232
233// Forward declaration in Macro.h, implementation here to avoid circular dependency
234template <typename TTarget, typename TSource>
235TTarget
237{
238#ifndef NDEBUG
239 if (x == nullptr)
240 {
241 return nullptr;
242 }
243 TTarget rval = dynamic_cast<TTarget>(x);
244 if (rval == nullptr)
245 {
246 itkGenericExceptionMacro("Failed dynamic cast to " << typeid(TTarget).name()
247 << " object type = " << x->GetNameOfClass());
248 }
249 return rval;
250#else
251 return static_cast<TTarget>(x);
252#endif
253}
254
255} // end namespace itk
256#endif // itkExceptionObject_h
Standard exception handling object.
virtual const char * GetLocation() const
const char * what() const noexcept override
virtual void SetDescription(const std::string &s)
static constexpr const char *const default_exception_message
virtual void SetLocation(const std::string &s)
std::shared_ptr< const ExceptionData > m_ExceptionData
ExceptionObject() noexcept=default
virtual const char * GetFile() const
virtual void Print(std::ostream &os) const
ExceptionObject(ExceptionObject &&) noexcept=default
virtual unsigned int GetLine() const
virtual const char * GetDescription() const
ExceptionObject(const ExceptionObject &) noexcept=default
ExceptionObject() noexcept=default
ExceptionObject() noexcept=default
ExceptionObject() noexcept=default
ProcessAborted(std::string file, unsigned int lineNumber)
ExceptionObject() noexcept=default
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
TTarget itkDynamicCastInDebugMode(TSource x)
STL namespace.