mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
refactor: Extract util/exception from util/system
This is a minimal extraction of a single function, but also the only use of std::exception in util/system. The background of this commit is an ongoing effort to decouple the libbitcoinkernel library from the ArgsManager defined in system.h. Moving the function out of system.h allows including it from a separate source file without including the ArgsManager definitions from system.h.
This commit is contained in:
parent
f7bdcfc83f
commit
e7333b420e
15 changed files with 69 additions and 30 deletions
|
@ -69,6 +69,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
|
|||
" src/util/bytevectorhash.cpp"\
|
||||
" src/util/check.cpp"\
|
||||
" src/util/error.cpp"\
|
||||
" src/util/exception.cpp"\
|
||||
" src/util/getuniquepath.cpp"\
|
||||
" src/util/hasher.cpp"\
|
||||
" src/util/message.cpp"\
|
||||
|
|
|
@ -279,6 +279,7 @@ BITCOIN_CORE_H = \
|
|||
util/check.h \
|
||||
util/epochguard.h \
|
||||
util/error.h \
|
||||
util/exception.h \
|
||||
util/fastrange.h \
|
||||
util/fees.h \
|
||||
util/getuniquepath.h \
|
||||
|
@ -699,6 +700,7 @@ libbitcoin_util_a_SOURCES = \
|
|||
util/bytevectorhash.cpp \
|
||||
util/check.cpp \
|
||||
util/error.cpp \
|
||||
util/exception.cpp \
|
||||
util/fees.cpp \
|
||||
util/getuniquepath.cpp \
|
||||
util/hasher.cpp \
|
||||
|
@ -942,6 +944,7 @@ libbitcoinkernel_la_SOURCES = \
|
|||
txmempool.cpp \
|
||||
uint256.cpp \
|
||||
util/check.cpp \
|
||||
util/exception.cpp \
|
||||
util/getuniquepath.cpp \
|
||||
util/hasher.cpp \
|
||||
util/moneystr.cpp \
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <rpc/request.h>
|
||||
#include <tinyformat.h>
|
||||
#include <univalue.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
|
|
|
@ -12,14 +12,15 @@
|
|||
#include <consensus/amount.h>
|
||||
#include <consensus/consensus.h>
|
||||
#include <core_io.h>
|
||||
#include <key_io.h>
|
||||
#include <fs.h>
|
||||
#include <key_io.h>
|
||||
#include <policy/policy.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/script.h>
|
||||
#include <script/sign.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <univalue.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/rbf.h>
|
||||
#include <util/strencodings.h>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <compat/compat.h>
|
||||
#include <core_io.h>
|
||||
#include <streams.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <version.h>
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <logging.h>
|
||||
#include <pubkey.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
#include <wallet/wallettool.h>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <noui.h>
|
||||
#include <shutdown.h>
|
||||
#include <util/check.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/syscall_sandbox.h>
|
||||
#include <util/syserror.h>
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <qt/utilitydialog.h>
|
||||
#include <qt/winshutdownmonitor.h>
|
||||
#include <uint256.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <protocol.h>
|
||||
#include <script/script.h>
|
||||
#include <script/standard.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/system.h>
|
||||
#include <util/time.h>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <qt/initexecutor.h>
|
||||
|
||||
#include <interfaces/node.h>
|
||||
#include <util/system.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/threadnames.h>
|
||||
|
||||
#include <exception>
|
||||
|
|
41
src/util/exception.cpp
Normal file
41
src/util/exception.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/exception.h>
|
||||
|
||||
#include <logging.h>
|
||||
#include <tinyformat.h>
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif // WIN32
|
||||
|
||||
static std::string FormatException(const std::exception* pex, std::string_view thread_name)
|
||||
{
|
||||
#ifdef WIN32
|
||||
char pszModule[MAX_PATH] = "";
|
||||
GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule));
|
||||
#else
|
||||
const char* pszModule = "bitcoin";
|
||||
#endif
|
||||
if (pex)
|
||||
return strprintf(
|
||||
"EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, thread_name);
|
||||
else
|
||||
return strprintf(
|
||||
"UNKNOWN EXCEPTION \n%s in %s \n", pszModule, thread_name);
|
||||
}
|
||||
|
||||
void PrintExceptionContinue(const std::exception* pex, std::string_view thread_name)
|
||||
{
|
||||
std::string message = FormatException(pex, thread_name);
|
||||
LogPrintf("\n\n************************\n%s\n", message);
|
||||
tfm::format(std::cerr, "\n\n************************\n%s\n", message);
|
||||
}
|
14
src/util/exception.h
Normal file
14
src/util/exception.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2023 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_UTIL_EXCEPTION_H
|
||||
#define BITCOIN_UTIL_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string_view>
|
||||
|
||||
void PrintExceptionContinue(const std::exception* pex, std::string_view thread_name);
|
||||
|
||||
#endif // BITCOIN_UTIL_EXCEPTION_H
|
|
@ -792,29 +792,6 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message
|
|||
std::string("\n\n");
|
||||
}
|
||||
|
||||
static std::string FormatException(const std::exception* pex, std::string_view thread_name)
|
||||
{
|
||||
#ifdef WIN32
|
||||
char pszModule[MAX_PATH] = "";
|
||||
GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule));
|
||||
#else
|
||||
const char* pszModule = "bitcoin";
|
||||
#endif
|
||||
if (pex)
|
||||
return strprintf(
|
||||
"EXCEPTION: %s \n%s \n%s in %s \n", typeid(*pex).name(), pex->what(), pszModule, thread_name);
|
||||
else
|
||||
return strprintf(
|
||||
"UNKNOWN EXCEPTION \n%s in %s \n", pszModule, thread_name);
|
||||
}
|
||||
|
||||
void PrintExceptionContinue(const std::exception* pex, std::string_view thread_name)
|
||||
{
|
||||
std::string message = FormatException(pex, thread_name);
|
||||
LogPrintf("\n\n************************\n%s\n", message);
|
||||
tfm::format(std::cerr, "\n\n************************\n%s\n", message);
|
||||
}
|
||||
|
||||
fs::path GetDefaultDataDir()
|
||||
{
|
||||
// Windows: C:\Users\Username\AppData\Roaming\Bitcoin
|
||||
|
|
|
@ -19,12 +19,10 @@
|
|||
#include <fs.h>
|
||||
#include <logging.h>
|
||||
#include <sync.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/settings.h>
|
||||
#include <util/time.h>
|
||||
|
||||
#include <any>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
@ -52,8 +50,6 @@ bool error(const char* fmt, const Args&... args)
|
|||
return false;
|
||||
}
|
||||
|
||||
void PrintExceptionContinue(const std::exception* pex, std::string_view thread_name);
|
||||
|
||||
/**
|
||||
* Ensure file contents are fully committed to disk, using a platform-specific
|
||||
* feature analogous to fsync().
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <util/thread.h>
|
||||
|
||||
#include <logging.h>
|
||||
#include <util/system.h>
|
||||
#include <util/exception.h>
|
||||
#include <util/threadnames.h>
|
||||
|
||||
#include <exception>
|
||||
|
|
Loading…
Add table
Reference in a new issue