1 /*=========================================================================
4 Module: $RCSfile: gdcmException.cxx,v $
6 Date: $Date: 2004/06/20 18:08:47 $
7 Version: $Revision: 1.16 $
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.htm 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 //-----------------------------------------------------------------------------
28 * \ingroup gdcmException
33 gdcmException::gdcmException(const std::string &f, const std::string& msg) throw()
37 : from(f), error(msg) {
41 fatal("gdcmException::gdcmException(const std::string&, const std::string&, const std::string&)");
47 * \ingroup gdcmException
51 void gdcmException::fatal(const char *from) throw() {
53 std::cerr << "Fatal: exception received in " << from
54 << " while handling exception." << std::endl;
59 std::cerr << "Fatal: exception received in Exception::fatal while handling exception."
70 * \ingroup gdcmException
74 std::string gdcmException::getName() const throw() {
76 #ifdef __GNUC__ // GNU C++ compiler class name demangling
77 unsigned int nested = 1, i, nb, offset;
81 std::string iname = typeid(*this).name();
83 nested = iname[1] - '0';
84 iname = std::string(iname, 2, std::string::npos);
86 for(i = 0; i < nested; i++) {
87 ::sscanf(iname.c_str(), "%u%n", &nb, &offset);
88 iname = std::string(iname, offset, std::string::npos);
89 name += std::string(iname, 0, nb);
90 if(i + 1 < nested) name += "::";
91 iname = std::string(iname, nb, std::string::npos);
94 #else // no class name demangling
95 //name = typeid(*this).name();
100 fatal("Exception::getName(std::string &)");
106 * \ingroup gdcmException
107 * \brief gdcmException
109 gdcmException::operator const char *() const throw() {
110 return getName().c_str();
113 //-----------------------------------------------------------------------------
115 * \ingroup gdcmException
116 * \brief gdcmException::operator <<
118 std::ostream& operator<<(std::ostream &os, const gdcmException &e) {
120 os << "Exception " << e.getName() << " thrown: " << e.getError() << std::endl;
123 gdcmException::fatal("operator<<(std::ostream &, const gdcmException&)");
128 //-----------------------------------------------------------------------------