1 /*=========================================================================
4 Module: $RCSfile: gdcmException.cxx,v $
6 Date: $Date: 2005/06/24 10:55:59 $
7 Version: $Revision: 1.27 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmException.h"
24 //-----------------------------------------------------------------------------
31 Exception::Exception(const std::string &f, const std::string &msg) throw()
41 fatal("Exception::Exception(const std::string&, const std::string&, const std::string&)");
49 void Exception::fatal(const char *from) throw()
53 std::cerr << "Fatal: exception received in " << from
54 << " while handling exception." << std::endl;
61 std::cerr << "Fatal: exception received in Exception::fatal while handling exception."
76 std::string Exception::getName() const throw()
80 #if defined(__GNUC__) && 0 // GNU C++ compiler class name demangling
81 unsigned int nested = 1, i, nb;
86 std::string iname = typeid(*this).name();
87 if ( iname[0] == 'Q' )
89 nested = iname[1] - '0';
90 iname = std::string(iname, 2, std::string::npos);
92 for(i = 0; i < nested; i++)
94 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
95 iname = std::string(iname, offset, std::string::npos);
96 name += std::string(iname, 0, nb);
97 if ( i + 1 < nested) name += "::";
98 iname = std::string(iname, nb, std::string::npos );
101 #else // no class name demangling
102 std::string name = typeid(*this).name();
108 fatal("Exception::getName(std::string &)");
116 Exception::operator const char *() const throw()
118 return getName().c_str();
121 //-----------------------------------------------------------------------------
123 * \brief Exception::operator <<
124 * @param os ostream to write to
125 * @param e exception to raise
127 std::ostream& operator<<(std::ostream &os, const Exception &e)
131 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
135 Exception::fatal("operator<<(std::ostream &, const Exception&)");
140 } // end namespace gdcm
141 //-----------------------------------------------------------------------------