9154f9b719
Summary: Added signal handler and refactored exception handler Test Plan: manual Reviewers: buda Subscribers: buda Differential Revision: https://memgraph.phacility.com/D17
36 lines
888 B
C++
36 lines
888 B
C++
#pragma once
|
|
|
|
#include "utils/auto_scope.hpp"
|
|
#include "utils/stacktrace.hpp"
|
|
|
|
#include <execinfo.h>
|
|
#include <iostream>
|
|
|
|
// TODO: log to local file or remote database
|
|
void stacktrace(std::ostream& stream) noexcept {
|
|
Stacktrace stacktrace;
|
|
|
|
std::string message;
|
|
|
|
for (int i = 0; i < stacktrace.size(); i++) {
|
|
message.append(fmt::format("\n at {} ({})", stacktrace[i].function,
|
|
stacktrace[i].location));
|
|
}
|
|
stream << message << std::endl;
|
|
}
|
|
|
|
// TODO: log to local file or remote database
|
|
void terminate_handler(std::ostream& stream) noexcept {
|
|
if (auto exc = std::current_exception()) {
|
|
try {
|
|
std::rethrow_exception(exc);
|
|
} catch (std::exception& ex) {
|
|
stream << ex.what() << std::endl << std::endl;
|
|
stacktrace(stream);
|
|
}
|
|
}
|
|
std::abort();
|
|
}
|
|
|
|
void terminate_handler() noexcept { terminate_handler(std::cout); }
|