blob: 09bb037d3ad0c6cdb360ff025448250581bc14e7 [file] [log] [blame]
Tomáš Peckaa193c032020-06-22 17:33:31 +02001/*
2 * Copyright (C) 2016-2019 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Jan Kundrát <jan.kundrat@cesnet.cz>
5 *
6*/
7
8#include <cxxabi.h>
9#include "utils/exceptions.h"
10#include "utils/log.h"
11
12namespace velia::utils {
13/** @short Log that everything is screwed up and rethrow
14
15The purpose is to make sure that a nicely formatted error message gets stored into the journald buffer with a high enough priority.
16*/
17void fatalException [[noreturn]] (velia::Log log, const std::exception& e, const std::string& when)
18{
19 int demangled;
Václav Kubernát4c388c82021-04-28 12:17:45 +020020 auto classname =
21 std::unique_ptr<char, decltype(&std::free)>(__cxxabiv1::__cxa_demangle(typeid(e).name(), nullptr, nullptr, &demangled), std::free);
22 log->critical("Fatal error in {}: {}", when, demangled == 0 ? classname.get() : typeid(e).name());
Tomáš Peckaa193c032020-06-22 17:33:31 +020023 log->critical("{}", e.what());
Tomáš Peckaa193c032020-06-22 17:33:31 +020024 throw;
25}
26}