Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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_INCLUDED
14 #define MITKEXCEPTION_H_INCLUDED
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(ClassName, SuperClassName);
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
static char * line
Definition: svm.cpp:2870
#define MITKCORE_EXPORT
Exception & operator<<(const T &data)
Definition of the bit shift operator for this class.
Definition: mitkException.h:74
std::vector< ReThrowData > m_RethrowData
DataCollection - Class to facilitate loading/accessing structured data.
~Exception() override
Definition: mitkException.h:53
MITKCORE_EXPORT std ::ostream & operator<<(std ::ostream &o, DataNode::Pointer &dtn)
Exception(const char *file, unsigned int lineNumber=0, const char *desc="None", const char *loc="Unknown")
Definition: mitkException.h:48
Exception & operator<<(T &data)
Definition of the bit shift operator for this class (for non const data).
Definition: mitkException.h:84
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
Exception & operator<<(std::ostream &(*func)(std::ostream &))
Definition of the bit shift operator for this class (for functions).
Definition: mitkException.h:93