rippled
Loading...
Searching...
No Matches
contract.h
1#ifndef XRPL_BASICS_CONTRACT_H_INCLUDED
2#define XRPL_BASICS_CONTRACT_H_INCLUDED
3
4#include <xrpl/beast/type_name.h>
5
6#include <exception>
7#include <string>
8#include <utility>
9
10namespace ripple {
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
28[[noreturn]] inline void
30{
31 LogThrow("Re-throwing exception");
32 throw;
33}
34
35template <class E, class... Args>
36[[noreturn]] inline void
37Throw(Args&&... args)
38{
39 static_assert(
41 "Exception must derive from std::exception.");
42
43 E e(std::forward<Args>(args)...);
46 "Throwing exception of type " + beast::type_name<E>() + ": ") +
47 e.what());
48 throw e;
49}
50
52[[noreturn]] void
53LogicError(std::string const& how) noexcept;
54
55} // namespace ripple
56
57#endif
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void Throw(Args &&... args)
Definition contract.h:37
void LogThrow(std::string const &title)
Generates and logs a call stack.
void Rethrow()
Rethrow the exception currently being handled.
Definition contract.h:29
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.