1 /*=========================================================================
4 Module: $RCSfile: gdcmException.cxx,v $
6 Date: $Date: 2004/10/08 04:52:55 $
7 Version: $Revision: 1.19 $
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"
23 //-----------------------------------------------------------------------------
27 * \ingroup gdcmException
32 gdcmException::gdcmException(const std::string &f, const std::string& msg) throw()
36 : From(f), Error(msg) {
40 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
46 * \ingroup gdcmException
50 void gdcmException::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."
73 * \ingroup gdcmException
77 std::string gdcmException::getName() const throw()
81 #ifdef __GNUC__ // GNU C++ compiler class name demangling
82 unsigned int nested = 1, i, nb, offset;
86 std::string iname = typeid(*this).name();
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 //name = typeid(*this).name();
107 fatal("Exception::getName(std::string &)");
113 * \ingroup gdcmException
114 * \brief gdcmException
116 gdcmException::operator const char *() const throw() {
117 return getName().c_str();
120 //-----------------------------------------------------------------------------
122 * \ingroup gdcmException
123 * \brief gdcmException::operator <<
125 std::ostream& operator<<(std::ostream &os, const gdcmException &e) {
127 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
130 gdcmException::fatal("operator<<(std::ostream &, const gdcmException&)");
135 //-----------------------------------------------------------------------------