Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
exception.hpp
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
10#pragma once
11
23#include <stdexcept>
24#include <string>
25
26namespace shambase {
27
39 std::string exception_format(SourceLocation loc);
40
42 using exception_gen_callback_t = void (*)(std::string msg);
43
54
63
81
90 void exception_gen_callback(std::string msg);
91
104 template<class ExcptTypes>
106 std::string message, SourceLocation loc = SourceLocation{}) {
107 std::string msg = message + exception_format(loc);
109 return ExcptTypes(msg);
110 }
111
131 template<class ExcptTypes>
135
154 throw_with_loc<std::runtime_error>("unimplemented", loc);
155 }
156
175 inline void throw_unimplemented(std::string message, SourceLocation loc = SourceLocation{}) {
176 throw_with_loc<std::runtime_error>(message + "\nunimplemented", loc);
177 }
178
179} // namespace shambase
Source location utility.
Scoped exception generator callback.
Definition exception.hpp:65
namespace for basic c++ utilities
void set_exception_gen_callback(exception_gen_callback_t callback)
Set the exception generator callback.
Definition exception.cpp:37
std::string exception_format(SourceLocation loc)
Format the exception message with the source location information.
Definition exception.cpp:24
void(*)(std::string msg) exception_gen_callback_t
type of the exception generator callback
Definition exception.hpp:42
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
void exception_gen_callback(std::string msg)
The callback called when an exception is thrown.
Definition exception.cpp:31
exception_gen_callback_t get_exception_gen_callback()
Get the current exception generator callback.
Definition exception.cpp:41
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
provide information about the source location