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&)");
21 void gdcmException::fatal(const char *from) throw() {
23 cerr << "Fatal: exception received in " << from
24 << " while handling exception." << endl;
29 cerr << "Fatal: exception received in Exception::fatal while handling exception."
40 string gdcmException::getName() const throw() {
42 #ifdef __GNUC__ // GNU C++ compiler class name demangling
43 unsigned int nested = 1, i, nb, offset;
47 string iname = typeid(*this).name();
49 nested = iname[1] - '0';
50 iname = string(iname, 2, std::string::npos);
52 for(i = 0; i < nested; i++) {
53 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
54 iname = string(iname, offset, std::string::npos);
55 name += string(iname, 0, nb);
56 if(i + 1 < nested) name += "::";
57 iname = string(iname, nb, std::string::npos);
60 #else // no class name demangling
61 //name = typeid(*this).name();
66 fatal("Exception::getName(string &)");
72 gdcmException::operator const char *() const throw() {
73 return getName().c_str();
77 ostream& operator<<(ostream &os, const gdcmException &e) {
79 os << "Exception " << e.getName() << " thrown: " << e.getError() << endl;
82 gdcmException::fatal("operator<<(ostream &, const gdcmException&)");