rippled
Loading...
Searching...
No Matches
contract.h
1#pragma once
2
3#include <xrpl/beast/type_name.h>
4
5#include <exception>
6#include <string>
7#include <utility>
8
9namespace xrpl {
10
11/* Programming By Contract
12
13 This routines are used when checking
14 preconditions, postconditions, and invariants.
15*/
16
18void
19LogThrow(std::string const& title);
20
27[[noreturn]] inline void
29{
30 LogThrow("Re-throwing exception");
31 throw;
32}
33
34template <class E, class... Args>
35[[noreturn]] inline void
36Throw(Args&&... args)
37{
38 static_assert(std::is_convertible<E*, std::exception*>::value, "Exception must derive from std::exception.");
39
40 E e(std::forward<Args>(args)...);
41 LogThrow(std::string("Throwing exception of type " + beast::type_name<E>() + ": ") + e.what());
42 throw e;
43}
44
46[[noreturn]] void
47LogicError(std::string const& how) noexcept;
48
49} // 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.
void LogThrow(std::string const &title)
Generates and logs a call stack.
void Throw(Args &&... args)
Definition contract.h:36
void Rethrow()
Rethrow the exception currently being handled.
Definition contract.h:28