aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2023-03-06 17:22:33 +0100
committerTheCharlatan <seb.kung@gmail.com>2023-03-13 17:09:47 +0100
commite7333b420e35054d9302f9c58fd47b6152cbd35f (patch)
treeb7dd521363eeedcc4e2f353624facbe8cc679372 /src/util
parentf7bdcfc83f5753349018be3b5a663c8923d1a5eb (diff)
downloadbitcoin-e7333b420e35054d9302f9c58fd47b6152cbd35f.tar.xz
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.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/exception.cpp41
-rw-r--r--src/util/exception.h14
-rw-r--r--src/util/system.cpp23
-rw-r--r--src/util/system.h4
-rw-r--r--src/util/thread.cpp2
5 files changed, 56 insertions, 28 deletions
diff --git a/src/util/exception.cpp b/src/util/exception.cpp
new file mode 100644
index 0000000000..d961f0540f
--- /dev/null
+++ b/src/util/exception.cpp
@@ -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);
+}
diff --git a/src/util/exception.h b/src/util/exception.h
new file mode 100644
index 0000000000..946eb2644c
--- /dev/null
+++ b/src/util/exception.h
@@ -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
diff --git a/src/util/system.cpp b/src/util/system.cpp
index 5b1a1659bf..98e89f82e7 100644
--- a/src/util/system.cpp
+++ b/src/util/system.cpp
@@ -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
diff --git a/src/util/system.h b/src/util/system.h
index f7bebe1f2a..2d07e64345 100644
--- a/src/util/system.h
+++ b/src/util/system.h
@@ -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().
diff --git a/src/util/thread.cpp b/src/util/thread.cpp
index e9f611bc50..f380d29f7a 100644
--- a/src/util/thread.cpp
+++ b/src/util/thread.cpp
@@ -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>