Initial code on crashes and exceptions logging. Related to T31.
This commit is contained in:
parent
aeb8586bfd
commit
9685ac3cb6
33
memgraph.cpp
33
memgraph.cpp
@ -12,8 +12,41 @@
|
||||
#include "threading/pool.hpp"
|
||||
#include "threading/task.hpp"
|
||||
|
||||
#include <execinfo.h>
|
||||
|
||||
// TODO: move to separate header or source file
|
||||
// TODO: log to local file or remote database
|
||||
void stacktrace() noexcept
|
||||
{
|
||||
void *array[50];
|
||||
int size = backtrace(array, 50);
|
||||
std::cout << __FUNCTION__ << " backtrace returned " << size << " frames\n\n";
|
||||
char **messages = backtrace_symbols(array, size);
|
||||
for (int i = 0; i < size && messages != NULL; ++i) {
|
||||
std::cout << "[bt]: (" << i << ") " << messages[i] << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
free(messages);
|
||||
}
|
||||
|
||||
// TODO: log to local file or remote database
|
||||
void on_terminate() noexcept
|
||||
{
|
||||
if (auto exc = std::current_exception()) {
|
||||
try {
|
||||
std::rethrow_exception(exc);
|
||||
} catch (std::exception &ex) {
|
||||
std::cout << ex.what() << std::endl << std::endl;
|
||||
stacktrace();
|
||||
}
|
||||
}
|
||||
std::_Exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::set_terminate(&on_terminate);
|
||||
|
||||
ioc::Container container;
|
||||
|
||||
container.singleton<Db>();
|
||||
|
Loading…
Reference in New Issue
Block a user