Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
exception.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16
22#include <string>
23
24namespace shambase {
25
27 return loc.format_multiline(fmt_callstack());
28 }
29
31 void (*exception_print_callback)(std::string msg) = nullptr;
32
33 void exception_gen_callback(std::string msg) {
34 if (exception_print_callback != nullptr) {
36 }
37 }
38
42
44
45 fmt::format_error format_exception_builder(
46 std::string_view function_call,
47 std::string_view what,
48 const std::string &fmt_string,
49 std::source_location loc) {
51 fmt::format(
52 "format failed:\n function={}\n what={}\n fmt_string={}",
53 function_call,
54 what,
55 fmt_string),
56 SourceLocation(loc));
57 }
58
59 static shambase::call_lambda register_format_exception_builder([]() {
60 sham::set_format_exception_builder(format_exception_builder);
61 });
62} // namespace shambase
Source location utility.
Call a lambda at static or local scope construction time.
This header file contains utility functions related to exception handling in the code.
Core formatting functions: format, vformat, and format_printf.
void set_format_exception_builder(format_except_builder_t callback)
Install a custom builder for format exceptions.
namespace for basic c++ utilities
std::string fmt_callstack()
Get the formatted callstack.
void set_exception_gen_callback(exception_gen_callback_t callback)
Set the exception generator callback.
Definition exception.cpp:39
std::string exception_format(SourceLocation loc)
Format the exception message with the source location information.
Definition exception.cpp:26
void(* exception_print_callback)(std::string msg)
exception print callback func ptr
Definition exception.cpp:31
void(*)(std::string msg) exception_gen_callback_t
type of the exception generator callback
Definition exception.hpp:42
void exception_gen_callback(std::string msg)
The callback called when an exception is thrown.
Definition exception.cpp:33
exception_gen_callback_t get_exception_gen_callback()
Get the current exception generator callback.
Definition exception.cpp:43
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
This file contains the definition for the stacktrace related functionality.
provide information about the source location
std::string format_multiline() const
format the location in multiple lines