1 /*=========================================================================
4 Module: $RCSfile: gdcmException.cxx,v $
6 Date: $Date: 2007/05/23 14:18:10 $
7 Version: $Revision: 1.29 $
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"
22 #include <stdlib.h> // for exit
24 namespace GDCM_NAME_SPACE
26 //-----------------------------------------------------------------------------
33 Exception::Exception(const std::string &f, const std::string &msg) throw()
43 fatal("Exception::Exception(const std::string&, const std::string&, const std::string&)");
51 void Exception::fatal(const char *from) throw()
55 std::cerr << "Fatal: exception received in " << from
56 << " while handling exception." << std::endl;
63 std::cerr << "Fatal: exception received in Exception::fatal while handling exception."
78 std::string Exception::getName() const throw()
82 #if defined(__GNUC__) && 0 // GNU C++ compiler class name demangling
83 unsigned int nested = 1, i, nb;
88 std::string iname = typeid(*this).name();
89 if ( iname[0] == 'Q' )
91 nested = iname[1] - '0';
92 iname = std::string(iname, 2, std::string::npos);
94 for(i = 0; i < nested; i++)
96 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
97 iname = std::string(iname, offset, std::string::npos);
98 name += std::string(iname, 0, nb);
99 if ( i + 1 < nested) name += "::";
100 iname = std::string(iname, nb, std::string::npos );
103 #else // no class name demangling
104 std::string name = typeid(*this).name();
110 fatal("Exception::getName(std::string &)");
118 Exception::operator const char *() const throw()
120 return getName().c_str();
123 //-----------------------------------------------------------------------------
125 * \brief Exception::operator <<
126 * @param os ostream to write to
127 * @param e exception to raise
129 std::ostream& operator<<(std::ostream &os, const Exception &e)
133 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
137 Exception::fatal("operator<<(std::ostream &, const Exception&)");
142 } // end namespace gdcm
143 //-----------------------------------------------------------------------------