2 //-----------------------------------------------------------------------------
3 #include "gdcmException.h"
8 //-----------------------------------------------------------------------------
12 * \ingroup gdcmException
17 gdcmException::gdcmException(const std::string &f, const std::string& msg) throw()
21 : from(f), error(msg) {
25 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
31 * \ingroup gdcmException
35 void gdcmException::fatal(const char *from) throw() {
37 std::cerr << "Fatal: exception received in " << from
38 << " while handling exception." << std::endl;
43 std::cerr << "Fatal: exception received in Exception::fatal while handling exception."
54 * \ingroup gdcmException
58 std::string gdcmException::getName() const throw() {
60 #ifdef __GNUC__ // GNU C++ compiler class name demangling
61 unsigned int nested = 1, i, nb, offset;
65 std::string iname = typeid(*this).name();
67 nested = iname[1] - '0';
68 iname = std::string(iname, 2, std::string::npos);
70 for(i = 0; i < nested; i++) {
71 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
72 iname = std::string(iname, offset, std::string::npos);
73 name += std::string(iname, 0, nb);
74 if(i + 1 < nested) name += "::";
75 iname = std::string(iname, nb, std::string::npos);
78 #else // no class name demangling
79 //name = typeid(*this).name();
84 fatal("Exception::getName(std::string &)");
90 * \ingroup gdcmException
91 * \brief gdcmException::operator
93 gdcmException::operator const char *() const throw() {
94 return getName().c_str();
97 //-----------------------------------------------------------------------------
99 * \ingroup gdcmException
100 * \brief gdcmException::operator <<
102 std::ostream& operator<<(std::ostream &os, const gdcmException &e) {
104 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
107 gdcmException::fatal("operator<<(std::ostream &, const gdcmException&)");
112 //-----------------------------------------------------------------------------