1 #include "gdcmException.h"
7 gdcmException::gdcmException(const string &f, const string& msg) throw()
11 : from(f), error(msg) {
15 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
20 void gdcmException::fatal(const char *from) throw() {
22 cerr << "Fatal: exception received in " << from
23 << " while handling exception." << endl;
28 cerr << "Fatal: exception received in Exception::fatal while handling exception."
39 string gdcmException::getName() const throw() {
41 #ifdef __GNUC__ // GNU C++ compiler class name demangling
42 unsigned int nested = 1, i, nb, offset;
46 string iname = typeid(*this).name();
48 nested = iname[1] - '0';
49 iname = string(iname, 2, std::string::npos);
51 for(i = 0; i < nested; i++) {
52 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
53 iname = string(iname, offset, std::string::npos);
54 name += string(iname, 0, nb);
55 if(i + 1 < nested) name += "::";
56 iname = string(iname, nb, std::string::npos);
59 #else // no class name demangling
60 //name = typeid(*this).name();
65 fatal("Exception::getName(string &)");
71 gdcmException::operator const char *() const throw() {
72 return getName().c_str();
76 ostream& operator<<(ostream &os, const gdcmException &e) {
78 os << "Exception " << e.getName() << " thrown: " << e.error << endl;
81 gdcmException::fatal("operator<<(ostream &, const gdcmException&)");