2 //-----------------------------------------------------------------------------
3 #include "gdcmException.h"
8 //-----------------------------------------------------------------------------
12 * \ingroup gdcmException
16 gdcmException::gdcmException(const std::string &f, const std::string& msg) throw()
20 : from(f), error(msg) {
24 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
30 * \ingroup gdcmException
34 void gdcmException::fatal(const char *from) throw() {
36 std::cerr << "Fatal: exception received in " << from
37 << " while handling exception." << std::endl;
42 std::cerr << "Fatal: exception received in Exception::fatal while handling exception."
53 * \ingroup gdcmException
57 std::string gdcmException::getName() const throw() {
59 #ifdef __GNUC__ // GNU C++ compiler class name demangling
60 unsigned int nested = 1, i, nb, offset;
64 std::string iname = typeid(*this).name();
66 nested = iname[1] - '0';
67 iname = std::string(iname, 2, std::string::npos);
69 for(i = 0; i < nested; i++) {
70 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
71 iname = std::string(iname, offset, std::string::npos);
72 name += std::string(iname, 0, nb);
73 if(i + 1 < nested) name += "::";
74 iname = std::string(iname, nb, std::string::npos);
77 #else // no class name demangling
78 //name = typeid(*this).name();
83 fatal("Exception::getName(std::string &)");
89 * \ingroup gdcmException
93 gdcmException::operator const char *() const throw() {
94 return getName().c_str();
97 //-----------------------------------------------------------------------------
99 * \ingroup gdcmException
103 std::ostream& operator<<(std::ostream &os, const gdcmException &e) {
105 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
108 gdcmException::fatal("operator<<(std::ostream &, const gdcmException&)");
113 //-----------------------------------------------------------------------------