Bitcoin ABC  0.22.12
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...


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 check; \
T get_pure_r_value(T &&val)
Helper for Assert().
Definition: check.h:52

Identity function.

Abort if the value compares equal to zero

Definition at line 57 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().

TODO remove in C++14 and replace decltype(get_pure_r_value(val)) with T (templated lambda)

Definition at line 52 of file check.h.