Bitcoin Core  0.20.99
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.

Classes

class  NonFatalCheckError
 

Macros

#define CHECK_NONFATAL(condition)
 Throw a NonFatalCheckError when the condition evaluates to false. More...
 
#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); }()
 Identity function. More...
 

Functions

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); }()

Identity function.

Abort if the value compares equal to zero

Definition at line 57 of file check.h.

◆ CHECK_NONFATAL

#define CHECK_NONFATAL (   condition)
Value:
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:1164
#define PACKAGE_BUGREPORT

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 32 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 51 of file check.h.