1 #include "gdcmException.h"
8 gdcmException::gdcmException(const string &f, const string& msg) throw()
12 : from(f), error(msg) {
16 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
22 void gdcmException::fatal(const char *from) throw() {
24 cerr << "Fatal: exception received in " << from
25 << " while handling exception." << endl;
30 cerr << "Fatal: exception received in Exception::fatal while handling exception."
41 string gdcmException::getName() const throw() {
43 #ifdef __GNUC__ // GNU C++ compiler class name demangling
44 unsigned int nested = 1, i, nb, offset;
48 string iname = typeid(*this).name();
50 nested = iname[1] - '0';
51 iname = string(iname, 2, std::string::npos);
53 for(i = 0; i < nested; i++) {
54 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
55 iname = string(iname, offset, std::string::npos);
56 name += string(iname, 0, nb);
57 if(i + 1 < nested) name += "::";
58 iname = string(iname, nb, std::string::npos);
61 #else // no class name demangling
62 //name = typeid(*this).name();
67 fatal("Exception::getName(string &)");
73 gdcmException::operator const char *() const throw() {
74 return getName().c_str();
78 ostream& operator<<(ostream &os, const gdcmException &e) {
80 os << "Exception " << e.getName() << " thrown: " << e.getError() << endl;
83 gdcmException::fatal("operator<<(ostream &, const gdcmException&)");