exception.C

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #include <iostream>
00021 
00022 #include <archon/util/exception.H>
00023 #include <archon/util/cxx_demangle.H>
00024 #include <archon/util/text.H>
00025 
00026 namespace Archon
00027 {
00028   namespace Utilities
00029   {
00030     bool exceptionCatchInfo(Exception::Formatter format, string &result)
00031     {
00032       try { throw; }
00033       catch(Exception &e)
00034       {
00035         result = (*format)(typeid(e), e.getLocation(), e.getMessage());
00036         return true;
00037       }
00038       catch(std::exception &e)
00039       {
00040         result = (*format)(typeid(e), "", e.what());
00041         return true;
00042       }
00043       catch(...) {}
00044       return false;
00045     }
00046 
00047     string Exception::explainLong(const type_info &t, string l, string m)
00048     {
00049       string s = "\n"
00050         "**************** CAUGHT EXCEPTION ****************\n"
00051         "\n"
00052         "Type:     " + cxxDemangle(t.name()) + "\n"
00053         "Location: " + (l.size() ? l : "N/A") + "\n"
00054         "Message:  " + (m.size() ? m : "N/A") + "\n"
00055         "\n";
00056       if(l.size()) s += "NB: Considder starting this program in 'gdb'\n"
00057                      "and set a break point at the indicated location.\n"
00058                      "This should give you the relevant stacktrace.\n"
00059                      "\n";
00060       return s;
00061     }
00062 
00063     string Exception::explainLongUnknown()
00064     {
00065       string s = "\n"
00066         "**************** CAUGHT EXCEPTION ****************\n"
00067         "\n"
00068         "Type:     N/A\n"
00069         "Location: N/A\n"
00070         "Message:  N/A\n"
00071         "\n";
00072       return s;
00073     }
00074 
00075     string Exception::explainShort(const type_info &t, string l, string m)
00076     {
00077       string s = cxxDemangle(t.name());
00078       if(l.size()) s += ": " + l;
00079       if(m.size()) s += ": " + m;
00080       return s;
00081     }
00082 
00083     string Exception::explainShortUnknown()
00084     {
00085       return "Unknown exception";
00086     }
00087 
00088     string Exception::line(long l)
00089     {
00090       return Text::toString(l);
00091     }
00092   }
00093 }
00094 

Generated on Sun Jul 30 22:55:41 2006 for Archon by  doxygen 1.4.4