Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkExceptionMacro.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 MITK_EXCEPTIONMACRO_H_DEFINED
18 #define MITK_EXCEPTIONMACRO_H_DEFINED
19 
20 #include "mitkException.h"
21 #include <itkMacro.h>
22 #include <mitkLogMacros.h>
23 #include <sstream>
24 
31 #define mitkThrow() throw mitk::Exception(__FILE__, __LINE__, "", ITK_LOCATION)
32 
49 #define mitkReThrow(mitkexception) \
50  mitkexception.AddRethrowData(__FILE__, __LINE__, "Rethrow by mitkReThrow macro."); \
51  throw mitkexception
52 
61 #define mitkThrowException(classname) throw classname(__FILE__, __LINE__, "", ITK_LOCATION)
62 
66 #define mitkExceptionClassMacro(ClassName, SuperClassName) \
67  ClassName(const char *file, unsigned int lineNumber, const char *desc, const char *loc) \
68  : SuperClassName(file, lineNumber, desc, loc) \
69  { \
70  } \
71  itkTypeMacro(ClassName, SuperClassName); \
72  \
73  template <class T> \
74  inline ClassName &operator<<(const T &data) \
75  { \
76  std::stringstream ss; \
77  ss << this->GetDescription() << data; \
78  this->SetDescription(ss.str()); \
79  return *this; \
80  } \
81  \
82  template <class T> \
83  inline ClassName &operator<<(T &data) \
84  { \
85  std::stringstream ss; \
86  ss << this->GetDescription() << data; \
87  this->SetDescription(ss.str()); \
88  return *this; \
89  } \
90  \
91  inline ClassName &operator<<(std::ostream &(*func)(std::ostream &)) \
92  { \
93  std::stringstream ss; \
94  ss << this->GetDescription() << func; \
95  this->SetDescription(ss.str()); \
96  return *this; \
97  }
98 
99 #endif