Bitcoin ABC 0.30.5
P2P Digital Currency
exception.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2023 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include <util/exception.h>
7
8#include <logging.h>
9#include <tinyformat.h>
10
11#include <exception>
12#include <iostream>
13#include <string>
14#include <typeinfo>
15
16#ifdef WIN32
17#include <windows.h>
18#endif // WIN32
19
20static std::string FormatException(const std::exception *pex,
21 const char *pszThread) {
22#ifdef WIN32
23 char pszModule[MAX_PATH] = "";
24 GetModuleFileNameA(nullptr, pszModule, sizeof(pszModule));
25#else
26 const char *pszModule = "bitcoin";
27#endif
28 if (pex) {
29 return strprintf("EXCEPTION: %s \n%s \n%s in %s \n",
30 typeid(*pex).name(), pex->what(), pszModule,
31 pszThread);
32 } else {
33 return strprintf("UNKNOWN EXCEPTION \n%s in %s \n",
34 pszModule, pszThread);
35 }
36}
37
38void PrintExceptionContinue(const std::exception *pex, const char *pszThread) {
39 std::string message = FormatException(pex, pszThread);
40 LogPrintf("\n\n************************\n%s\n", message);
41 tfm::format(std::cerr, "\n\n************************\n%s\n", message);
42}
#define MAX_PATH
Definition: compat.h:70
static std::string FormatException(const std::exception *pex, const char *pszThread)
Definition: exception.cpp:20
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
Definition: exception.cpp:38
#define LogPrintf(...)
Definition: logging.h:207
void format(std::ostream &out, const char *fmt, const Args &...args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1112
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202