GDCM  2.4.5
gdcmException.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: GDCM (Grassroots DICOM). A DICOM library
4 
5  Copyright (c) 2006-2011 Mathieu Malaterre
6  All rights reserved.
7  See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef GDCMEXCEPTION_H
15 #define GDCMEXCEPTION_H
16 
17 #include <cassert>
18 #include <cstdlib> // NULL
19 #include <exception>
20 #include <sstream> // ostringstream
21 #include <stdexcept> // logic_error
22 #include <string>
23 
24 // Disable clang warning "dynamic exception specifications are deprecated".
25 // We need to be C++03 and C++11 compatible, and if we remove the 'throw()'
26 // specifier we'll get an error in C++03 by not matching the superclass.
27 #if defined(__clang__) && defined(__has_warning)
28 # if __has_warning("-Wdeprecated")
29 # pragma clang diagnostic push
30 # pragma clang diagnostic ignored "-Wdeprecated"
31 # endif
32 #endif
33 
34 namespace gdcm
35 {
36 
43 class Exception : public std::exception
44 {
49  typedef std::logic_error StringHolder;
50 
52  static StringHolder CreateWhat(const char* const desc,
53  const char* const file,
54  const unsigned int lineNumber,
55  const char* const func)
56  {
57  assert(desc != NULL);
58  assert(file != NULL);
59  assert(func != NULL);
60  std::ostringstream oswhat;
61  oswhat << file << ":" << lineNumber << " (" << func << "):\n";
62  oswhat << desc;
63  return StringHolder( oswhat.str() );
64  }
65 
66 public:
72  explicit Exception(const char *desc = "None",
73  const char *file = __FILE__,
74  unsigned int lineNumber = __LINE__,
75  // FIXME: __PRETTY_FUNCTION__ is the non-mangled version for __GNUC__ compiler
76  const char *func = "" /*__FUNCTION__*/)
77  :
78  What( CreateWhat(desc, file, lineNumber, func) ),
79  Description(desc)
80  {
81  }
82 
83  virtual ~Exception() throw() {}
84 
86  const char* what() const throw()
87  {
88  return What.what();
89  }
90 
92  const char * GetDescription() const { return Description.what(); }
93 
94 private:
95  StringHolder What;
96  StringHolder Description;
97 };
98 
99 } // end namespace gdcm
100 
101 // Undo warning suppression.
102 #if defined(__clang__) && defined(__has_warning)
103 # if __has_warning("-Wdeprecated")
104 # pragma clang diagnostic pop
105 # endif
106 #endif
107 
108 #endif
const char * what() const
what implementation
Definition: gdcmException.h:86
const char * GetDescription() const
Return the Description.
Definition: gdcmException.h:92
virtual ~Exception()
Definition: gdcmException.h:83
Definition: gdcmASN1.h:20
Exception.
Definition: gdcmException.h:43
Exception(const char *desc="None", const char *file=__FILE__, unsigned int lineNumber=__LINE__, const char *func="")
Definition: gdcmException.h:72

Generated on Fri Sep 25 2015 17:58:23 for GDCM by doxygen 1.8.9.1
SourceForge.net Logo