Medical Imaging Interaction Toolkit  2024.12.99-0da743f6
Medical Imaging Interaction Toolkit
mitkException.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkException_h
14 #define mitkException_h
15 
16 #include <MitkCoreExports.h>
17 #include <itkMacro.h>
18 #include <vector>
19 
20 namespace mitk
21 {
45  class MITKCORE_EXPORT Exception : public itk::ExceptionObject
46  {
47  public:
48  Exception(const char *file, unsigned int lineNumber = 0, const char *desc = "None", const char *loc = "Unknown")
49  : itk::ExceptionObject(file, lineNumber, desc, loc)
50  {
51  }
52 
53  ~Exception() throw() override {}
54  itkTypeMacro(Exception, itk::ExceptionObject);
55 
57  void AddRethrowData(const char *file, unsigned int lineNumber, const char *message);
58 
60  int GetNumberOfRethrows();
61 
70  void GetRethrowData(int rethrowNumber, std::string &file, int &line, std::string &message);
71 
73  template <class T>
74  inline Exception &operator<<(const T &data)
75  {
76  std::stringstream ss;
77  ss << this->GetDescription() << data;
78  this->SetDescription(ss.str());
79  return *this;
80  }
81 
83  template <class T>
84  inline Exception &operator<<(T &data)
85  {
86  std::stringstream ss;
87  ss << this->GetDescription() << data;
88  this->SetDescription(ss.str());
89  return *this;
90  }
91 
93  inline Exception &operator<<(std::ostream &(*func)(std::ostream &))
94  {
95  std::stringstream ss;
96  ss << this->GetDescription() << func;
97  this->SetDescription(ss.str());
98  return *this;
99  }
100 
101  protected:
102  struct ReThrowData
103  {
104  std::string RethrowClassname;
105  unsigned int RethrowLine;
106  std::string RethrowMessage;
107  };
108 
109  std::vector<ReThrowData> m_RethrowData;
110  };
111 
112  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &os, const mitk::Exception &e);
113 } // namespace mitk
114 
115 #endif
mitk::Exception
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:45
mitk::Exception::m_RethrowData
std::vector< ReThrowData > m_RethrowData
Definition: mitkException.h:109
mitk::Exception::operator<<
Exception & operator<<(std::ostream &(*func)(std::ostream &))
Definition of the bit shift operator for this class (for functions).
Definition: mitkException.h:93
mitk::Exception::ReThrowData
Definition: mitkException.h:102
mitk::operator<<
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
mitk::Exception::~Exception
~Exception() override
Definition: mitkException.h:53
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::Exception::Exception
Exception(const char *file, unsigned int lineNumber=0, const char *desc="None", const char *loc="Unknown")
Definition: mitkException.h:48
MitkCoreExports.h
mitk::Exception::operator<<
Exception & operator<<(T &data)
Definition of the bit shift operator for this class (for non const data).
Definition: mitkException.h:84
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
mitk::Exception::ReThrowData::RethrowLine
unsigned int RethrowLine
Definition: mitkException.h:105
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::Exception::ReThrowData::RethrowClassname
std::string RethrowClassname
Definition: mitkException.h:104
mitk::Exception::ReThrowData::RethrowMessage
std::string RethrowMessage
Definition: mitkException.h:106
mitk::Exception::operator<<
Exception & operator<<(const T &data)
Definition of the bit shift operator for this class.
Definition: mitkException.h:74