rippled
Loading...
Searching...
No Matches
contract.h
1#pragma once
2
3#include <xrpl/basics/sanitizers.h>
4#include <xrpl/beast/type_name.h>
5
6#include <exception>
7#include <string>
8#include <utility>
9
10namespace xrpl {
11
12/* Programming By Contract
13
14 This routines are used when checking
15 preconditions, postconditions, and invariants.
16*/
17
19void
20LogThrow(std::string const& title);
21
32[[noreturn]] XRPL_NO_SANITIZE_ADDRESS inline void
34{
35 LogThrow("Re-throwing exception");
36 throw;
37}
38
39/*
40 Logs and throws an exception of type E.
41
42 ASAN can't handle sudden jumps in control flow very well. This
43 function is marked as XRPL_NO_SANITIZE_ADDRESS to prevent it from
44 triggering false positives, since it throws.
45*/
46
47template <class E, class... Args>
48[[noreturn]] XRPL_NO_SANITIZE_ADDRESS inline void
49Throw(Args&&... args)
50{
51 static_assert(
53 "Exception must derive from std::exception.");
54
55 E e(std::forward<Args>(args)...);
56 LogThrow(std::string("Throwing exception of type " + beast::type_name<E>() + ": ") + e.what());
57 throw std::move(e);
58}
59
61[[noreturn]] void
62LogicError(std::string const& how) noexcept;
63
64} // namespace xrpl
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
XRPL_NO_SANITIZE_ADDRESS void Rethrow()
Rethrow the exception currently being handled.
Definition contract.h:33
void LogThrow(std::string const &title)
Generates and logs a call stack.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:49