Dune::Copasi
Loading...
Searching...
No Matches
exceptions.hh
Go to the documentation of this file.
1#ifndef DUNE_COPASI_COMMON_EXCEPTION_HH
2#define DUNE_COPASI_COMMON_EXCEPTION_HH
3
4#include <dune-copasi-config.hh>
5
6#include <dune/common/classname.hh>
7
8#include <fmt/core.h>
9
10#include <utility>
11#if __has_include(<stacktrace>)
12#include <stacktrace>
13#endif
14
15#if __has_include(<format>)
16#include <format>
17#endif
18
19namespace Dune::Copasi {
20
21template<typename Exception, typename... Args>
22[[nodiscard]] inline auto
23format_exception(Exception&& e, fmt::format_string<Args...> format, Args&&... args)
24{
25 auto message = std::string{"Message: "};
26 message += fmt::format(std::move(format), std::forward<Args>(args)...);
27 message += fmt::format("\nException type: {}", className<Exception>());
28#if ___cpp_lib_stacktrace >= 202011L && __cpp_lib_formatters >= 202302L
29 message += std::format("\nStacktrace:\n{}", std::stacktrace::current());
30#endif
31 e.message(message);
32 return std::forward<Exception>(e);
33}
34
35} // namespace Dune::Copasi
36
37#endif // DUNE_COPASI_COMMON_EXCEPTION_HH
Definition axis_names.hh:7
auto format_exception(Exception &&e, fmt::format_string< Args... > format, Args &&... args)
Definition exceptions.hh:23
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24