Medical Imaging Interaction Toolkit  2026.06.00
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 {
52  class MITKCORE_EXPORT Exception : public itk::ExceptionObject
53  {
54  public:
62  Exception(const char *file, unsigned int lineNumber = 0, const char *desc = "None", const char *loc = "Unknown")
63  : itk::ExceptionObject(file, lineNumber, desc, loc)
64  {
65  }
66 
68  ~Exception() throw() override {}
69  itkTypeMacro(Exception, itk::ExceptionObject);
70 
83  void AddRethrowData(const char *file, unsigned int lineNumber, const char *message);
84 
90 
104  void GetRethrowData(int rethrowNumber, std::string &file, int &line, std::string &message);
105 
112  template <class T>
113  inline Exception &operator<<(const T &data)
114  {
115  std::stringstream ss;
116  ss << this->GetDescription() << data;
117  this->SetDescription(ss.str());
118  return *this;
119  }
120 
127  template <class T>
128  inline Exception &operator<<(T &data)
129  {
130  std::stringstream ss;
131  ss << this->GetDescription() << data;
132  this->SetDescription(ss.str());
133  return *this;
134  }
135 
141  inline Exception &operator<<(std::ostream &(*func)(std::ostream &))
142  {
143  std::stringstream ss;
144  ss << this->GetDescription() << func;
145  this->SetDescription(ss.str());
146  return *this;
147  }
148 
149  protected:
151  struct ReThrowData
152  {
153  std::string RethrowClassname;
154  unsigned int RethrowLine;
155  std::string RethrowMessage;
156  };
157 
159  std::vector<ReThrowData> m_RethrowData;
160  };
161 
171  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &os, const mitk::Exception &e);
172 } // namespace mitk
173 
174 #endif
#define MITKCORE_EXPORT
Base class for all MITK exceptions.
Definition: mitkException.h:53
std::vector< ReThrowData > m_RethrowData
List of recorded rethrow contexts.
void AddRethrowData(const char *file, unsigned int lineNumber, const char *message)
Record additional rethrow context for this exception.
Exception & operator<<(std::ostream &(*func)(std::ostream &))
Append a stream manipulator (e.g. std::endl) to the exception description.
Exception(const char *file, unsigned int lineNumber=0, const char *desc="None", const char *loc="Unknown")
Construct an exception with source location and description.
Definition: mitkException.h:62
Exception & operator<<(const T &data)
Append data to the exception description via the stream operator.
int GetNumberOfRethrows()
Return the number of times this exception has been rethrown.
~Exception() override
Destructor.
Definition: mitkException.h:68
void GetRethrowData(int rethrowNumber, std::string &file, int &line, std::string &message)
Retrieve the rethrow context for a specific rethrow.
Exception & operator<<(T &data)
Append non-const data to the exception description via the stream operator.
Find image slices visible on a given plane.
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
Stream output operator for DataNode smart pointers.
Internal storage for a single rethrow record.
std::string RethrowClassname
Source file of the rethrow.
std::string RethrowMessage
Message associated with the rethrow.
unsigned int RethrowLine
Line number of the rethrow.