Bitcoin Core 28.99.0
P2P Digital Currency
check.cpp
Go to the documentation of this file.
1// Copyright (c) 2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <util/check.h>
6
7#include <bitcoin-build-config.h> // IWYU pragma: keep
8
9#include <clientversion.h>
10#include <tinyformat.h>
11
12#include <cstdio>
13#include <cstdlib>
14#include <string>
15#include <string_view>
16
17std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
18{
19 return strprintf("Internal bug detected: %s\n%s:%d (%s)\n"
20 "%s %s\n"
21 "Please report this issue here: %s\n",
22 msg, file, line, func, CLIENT_NAME, FormatFullVersion(), CLIENT_BUGREPORT);
23}
24
25NonFatalCheckError::NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
26 : std::runtime_error{StrFormatInternalBug(msg, file, line, func)}
27{
28}
29
30void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
31{
32 auto str = strprintf("%s:%s %s: Assertion `%s' failed.\n", file, line, func, assertion);
33 fwrite(str.data(), 1, str.size(), stderr);
34 std::abort();
35}
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
Definition: check.cpp:17
void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
Helper for Assert()
Definition: check.cpp:30
NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
Definition: check.cpp:25
std::string FormatFullVersion()
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1165