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