ITK  4.8.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 itkMacro_h
19 #error "Do not include itkExceptionObject.h directly, include itkMacro.h instead."
20 #else // itkMacro_h
21 
22 #ifndef itkExceptionObject_h
23 #define itkExceptionObject_h
24 
25 #include <string>
26 #include <stdexcept>
27 
28 #include "itkSmartPointer.h"
29 
30 namespace itk
31 {
51 class ITKCommon_EXPORT ExceptionObject:public std::exception
52 {
53 public:
54  typedef std::exception Superclass;
59  explicit ExceptionObject(const char *file, unsigned int lineNumber = 0,
60  const char *desc = "None", const char *loc = "Unknown");
61  explicit ExceptionObject(const std::string & file, unsigned int lineNumber = 0,
62  const std::string & desc = "None",
63  const std::string & loc = "Unknown");
64  ExceptionObject(const ExceptionObject & orig);
66 
68  virtual ~ExceptionObject()
69  ITK_NOEXCEPT;
70 
72  ExceptionObject & operator=(const ExceptionObject & orig);
73 
75  virtual bool operator==(const ExceptionObject & orig);
76 
77  virtual const char * GetNameOfClass() const
78  { return "ExceptionObject"; }
79 
84  virtual void Print(std::ostream & os) const;
85 
89  virtual void SetLocation(const std::string & s);
90 
91  virtual void SetDescription(const std::string & s);
92 
93  virtual void SetLocation(const char *s);
94 
95  virtual void SetDescription(const char *s);
96 
97  virtual const char * GetLocation() const;
98 
99  virtual const char * GetDescription() const;
100 
102  virtual const char * GetFile() const;
103 
105  virtual unsigned int GetLine() const;
106 
108  virtual const char * what() const ITK_NOEXCEPT ITK_OVERRIDE;
109 
110 private:
137  {
138 public:
139  virtual void Register() const = 0;
140 
141  virtual void UnRegister() const = 0;
142 
143  ReferenceCounterInterface();
144  virtual ~ReferenceCounterInterface();
145  };
146  class ExceptionData;
147  class ReferenceCountedExceptionData;
149  const ExceptionData * GetExceptionData() const;
150 };
151 
153 inline std::ostream & operator<<(std::ostream & os, ExceptionObject & e)
154 {
155  ( &e )->Print(os);
156  return os;
157 }
159 
169 class ITKCommon_EXPORT MemoryAllocationError:public ExceptionObject
170 {
171 public:
175 
177  MemoryAllocationError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
178 
180  MemoryAllocationError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
181 
183  MemoryAllocationError(const std::string & file,
184  unsigned int lineNumber,
185  const std::string & desc,
186  const std::string & loc):ExceptionObject(file, lineNumber, desc, loc) {}
187 
189  virtual ~MemoryAllocationError() ITK_NOEXCEPT;
190 
191  virtual const char * GetNameOfClass() const ITK_OVERRIDE
192  { return "MemoryAllocationError"; }
193 };
194 
200 class ITKCommon_EXPORT RangeError:public ExceptionObject
201 {
202 public:
206 
208  RangeError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
209 
211  RangeError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
212 
214  virtual ~RangeError() ITK_NOEXCEPT;
215 
216  virtual const char * GetNameOfClass() const ITK_OVERRIDE
217  { return "RangeError"; }
218 };
219 
226 class ITKCommon_EXPORT InvalidArgumentError:public ExceptionObject
227 {
228 public:
234 
238  InvalidArgumentError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
239 
243  InvalidArgumentError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
244 
246  virtual ~InvalidArgumentError() ITK_NOEXCEPT;
247 
248  virtual const char * GetNameOfClass() const ITK_OVERRIDE
249  { return "InvalidArgumentError"; }
250 };
251 
257 class ITKCommon_EXPORT IncompatibleOperandsError:public ExceptionObject
258 {
259 public:
263 
265  IncompatibleOperandsError(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
266 
268  IncompatibleOperandsError(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber) {}
269 
271  virtual ~IncompatibleOperandsError() ITK_NOEXCEPT;
272 
273  virtual const char * GetNameOfClass() const ITK_OVERRIDE
274  { return "IncompatibleOperandsError"; }
275 };
276 
282 class ITKCommon_EXPORT ProcessAborted:public ExceptionObject
283 {
284 public:
288  {
289  this->SetDescription("Filter execution was aborted by an external request");
290  }
291 
293  ProcessAborted(const char *file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
294  {
295  this->SetDescription("Filter execution was aborted by an external request");
296  }
297 
299  ProcessAborted(const std::string & file, unsigned int lineNumber):ExceptionObject(file, lineNumber)
300  {
301  this->SetDescription("Filter execution was aborted by an external request");
302  }
303 
305  virtual ~ProcessAborted() ITK_NOEXCEPT;
306 
307  virtual const char * GetNameOfClass() const ITK_OVERRIDE
308  { return "ProcessAborted"; }
309 };
310 } // end namespace itk
311 
312 #endif //itkExceptionObject_h
313 
314 #endif //itkMacro_h
ProcessAborted(const std::string &file, unsigned int lineNumber)
InvalidArgumentError(const char *file, unsigned int lineNumber)
IncompatibleOperandsError(const char *file, unsigned int lineNumber)
RangeError(const std::string &file, unsigned int lineNumber)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
ProcessAborted(const char *file, unsigned int lineNumber)
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
Standard exception handling object.
SmartPointer< const ReferenceCounterInterface > m_ExceptionData
InvalidArgumentError(const std::string &file, unsigned int lineNumber)
MemoryAllocationError(const std::string &file, unsigned int lineNumber, const std::string &desc, const std::string &loc)
MemoryAllocationError(const std::string &file, unsigned int lineNumber)
Implements transparent reference counting.
RangeError(const char *file, unsigned int lineNumber)
IncompatibleOperandsError(const std::string &file, unsigned int lineNumber)
MemoryAllocationError(const char *file, unsigned int lineNumber)
std::exception Superclass