Tomáš Pecka | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | namespace velia::utils { |
| 13 | /** @short Log that everything is screwed up and rethrow |
| 14 | |
| 15 | The purpose is to make sure that a nicely formatted error message gets stored into the journald buffer with a high enough priority. |
| 16 | */ |
| 17 | void fatalException [[noreturn]] (velia::Log log, const std::exception& e, const std::string& when) |
| 18 | { |
| 19 | int demangled; |
Václav Kubernát | 4c388c8 | 2021-04-28 12:17:45 +0200 | [diff] [blame] | 20 | 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áš Pecka | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 23 | log->critical("{}", e.what()); |
Tomáš Pecka | a193c03 | 2020-06-22 17:33:31 +0200 | [diff] [blame] | 24 | throw; |
| 25 | } |
| 26 | } |