Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKEXCEPTION_H_INCLUDED
18 #define MITKEXCEPTION_H_INCLUDED
19 
20 #include <MitkCoreExports.h>
21 #include <itkMacro.h>
22 #include <vector>
23 
24 namespace mitk
25 {
49  class MITKCORE_EXPORT Exception : public itk::ExceptionObject
50  {
51  public:
52  Exception(const char *file, unsigned int lineNumber = 0, const char *desc = "None", const char *loc = "Unknown")
53  : itk::ExceptionObject(file, lineNumber, desc, loc)
54  {
55  }
56 
57  virtual ~Exception() throw() {}
58  itkTypeMacro(ClassName, SuperClassName);
59 
61  void AddRethrowData(const char *file, unsigned int lineNumber, const char *message);
62 
64  int GetNumberOfRethrows();
65 
74  void GetRethrowData(int rethrowNumber, std::string &file, int &line, std::string &message);
75 
77  template <class T>
78  inline Exception &operator<<(const T &data)
79  {
80  std::stringstream ss;
81  ss << this->GetDescription() << data;
82  this->SetDescription(ss.str());
83  return *this;
84  }
85 
87  template <class T>
88  inline Exception &operator<<(T &data)
89  {
90  std::stringstream ss;
91  ss << this->GetDescription() << data;
92  this->SetDescription(ss.str());
93  return *this;
94  }
95 
97  inline Exception &operator<<(std::ostream &(*func)(std::ostream &))
98  {
99  std::stringstream ss;
100  ss << this->GetDescription() << func;
101  this->SetDescription(ss.str());
102  return *this;
103  }
104 
105  protected:
106  struct ReThrowData
107  {
108  std::string RethrowClassname;
109  unsigned int RethrowLine;
110  std::string RethrowMessage;
111  };
112 
113  std::vector<ReThrowData> m_RethrowData;
114  };
115 
116  MITKCORE_EXPORT std::ostream &operator<<(std::ostream &os, const mitk::Exception &e);
117 } // namespace mitk
118 
119 #endif
static char * line
Definition: svm.cpp:2884
#define MITKCORE_EXPORT
MITKCORE_EXPORT std::ostream & operator<<(std::ostream &o, DataNode::Pointer &dtn)
Exception & operator<<(const T &data)
Definition of the bit shift operator for this class.
Definition: mitkException.h:78
std::vector< ReThrowData > m_RethrowData
DataCollection - Class to facilitate loading/accessing structured data.
Exception(const char *file, unsigned int lineNumber=0, const char *desc="None", const char *loc="Unknown")
Definition: mitkException.h:52
Exception & operator<<(T &data)
Definition of the bit shift operator for this class (for non const data).
Definition: mitkException.h:88
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
Exception & operator<<(std::ostream &(*func)(std::ostream &))
Definition of the bit shift operator for this class (for functions).
Definition: mitkException.h:97
virtual ~Exception()
Definition: mitkException.h:57