Bitcoin ABC  0.26.3
P2P Digital Currency
Classes | Macros | Functions
check.h File Reference
#include <tinyformat.h>
#include <stdexcept>
Include dependency graph for check.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


class  NonFatalCheckError


#define CHECK_NONFATAL(condition)
 Throw a NonFatalCheckError when the condition evaluates to false. More...
#define Assert(val)
 Identity function. More...
#define Assume(val)
 Assume is the identity function. More...


template<typename T >
get_pure_r_value (T &&val)
 Helper for Assert() More...

Macro Definition Documentation

◆ Assert

#define Assert (   val)
([&]() -> decltype(get_pure_r_value(val)) { \
auto &&check = (val); \
assert(#val &&check); \
return std::forward<decltype(get_pure_r_value(val))>(check); \
T get_pure_r_value(T &&val)
Helper for Assert()
Definition: check.h:51

Identity function.

Abort if the value compares equal to zero

Definition at line 56 of file check.h.

◆ Assume

#define Assume (   val)
([&]() -> decltype(get_pure_r_value(val)) { \
auto &&check = (val); \
return std::forward<decltype(get_pure_r_value(val))>(check); \

Assume is the identity function.

  • Should be used to run non-fatal checks. In debug builds it behaves like Assert()/assert() to notify developers and testers about non-fatal errors. In production it doesn't warn or log anything.
  • For fatal errors, use Assert().
  • For non-fatal errors in interactive sessions (e.g. RPC or command line interfaces), CHECK_NONFATAL() might be more appropriate.

Definition at line 76 of file check.h.


#define CHECK_NONFATAL (   condition)
do { \
if (!(condition)) { \
strprintf("%s:%d (%s)\n" \
"Internal bug detected: '%s'\n" \
"You may report this issue here: %s\n", \
__FILE__, __LINE__, __func__, (#condition), \
} \
} while (false)
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201

Throw a NonFatalCheckError when the condition evaluates to false.

This should only be used

  • where the condition is assumed to be true, not for error handling or validating user input
  • where a failure to fulfill the condition is recoverable and does not abort the program

For example in RPC code, where it is undesirable to crash the whole program, this can be generally used to replace asserts or recoverable logic errors. A NonFatalCheckError in RPC code is caught and passed as a string to the RPC caller, which can then report the issue to the developers.

Definition at line 34 of file check.h.

Function Documentation

◆ get_pure_r_value()

template<typename T >
T get_pure_r_value ( T &&  val)

Helper for Assert()

Definition at line 51 of file check.h.