42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
|
|
#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;
|
||
|
|
|
||
|
|
}
|