00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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