GDCM  2.2.0
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 namespace gdcm
25 {
26 
33 class Exception : public std::exception
34 {
39  typedef std::logic_error StringHolder;
40 
42  static StringHolder CreateWhat(const char* const desc,
43  const char* const file,
44  const unsigned int lineNumber,
45  const char* const func)
46  {
47  assert(desc != NULL);
48  assert(file != NULL);
49  assert(func != NULL);
50  std::ostringstream oswhat;
51  oswhat << file << ":" << lineNumber << " (" << func << "):\n";
52  oswhat << desc;
53  return StringHolder( oswhat.str() );
54  }
55 
56 public:
62  explicit Exception(const char *desc = "None",
63  const char *file = __FILE__,
64  unsigned int lineNumber = __LINE__,
65  // FIXME: __PRETTY_FUNCTION__ is the non-mangled version for __GNUC__ compiler
66  const char *func = "" /*__FUNCTION__*/)
67  :
68  What( CreateWhat(desc, file, lineNumber, func) ),
69  Description(desc)
70  {
71  }
72 
73  virtual ~Exception() throw() {}
74 
76  const char* what() const throw()
77  {
78  return What.what();
79  }
80 
82  const char * GetDescription() const { return Description.what(); }
83 
84 private:
85  StringHolder What;
86  StringHolder Description;
87 };
88 
89 } // end namespace gdcm
90 
91 #endif

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo