Files
mrw-cxx/mrw/autostacktracestderr.cpp

42 lines
1.2 KiB
C++
Raw Normal View History

2004-04-21 06:39:20 +00:00
#include <mrw/stacktrace.hpp>
#include <mrw/exception.hpp>
#include <exception>
#include <iostream>
namespace mrw {
/// @todo integrate it into the distribution and document it
void unexpected() {
std::cerr<<"UNEXPECTED EXCEPTION: ----------------------------"<<std::endl;
try {
throw;
} catch (const mrw::exception& x) {
StackTrace::createSymtable();
std::cerr<<"---------- Reason:"<<std::endl
<<x.what()<<std::endl
<<"---------- Stack:"<<std::endl
<<x.stacktrace()<<std::endl;
} catch (const std::exception& x) {
std::cerr<<"---------- Reason:"<<std::endl
<<x.what()<<std::endl
<<"---------- Stack: **** not available ****"<<std::endl;
} catch (...) {
std::cerr<<"---------- Reason: **** not available ****"<<std::endl
<<"---------- Stack: **** not available ****"<<std::endl;
}
std::cerr<<"-------------------------------------------------"<<std::endl;
throw std::bad_exception();
}
class AutoStackTrace {
public:
AutoStackTrace() {
std::set_unexpected(&mrw::unexpected);
}
};
// initialize stack traces (load symbols)
static AutoStackTrace _autoStackTrace;
}