aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/error.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-09-20 00:09:34 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-09-20 00:12:50 +0300
commit1cbd0a3b824d1821549b4c7ede688f500de25443 (patch)
treed7771d4afeb9609758c9f632674081091f99ed67 /src/error.cpp
parentpdb::file: use wide WinAPI (diff)
downloadwinapi-debug-1cbd0a3b824d1821549b4c7ede688f500de25443.tar.gz
winapi-debug-1cbd0a3b824d1821549b4c7ede688f500de25443.zip
pdb::error: include function name in error message
Diffstat (limited to 'src/error.cpp')
-rw-r--r--src/error.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/error.cpp b/src/error.cpp
index 74cf395..368feb7 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -9,7 +9,9 @@
#include <windows.h>
+#include <sstream>
#include <string>
+#include <system_error>
namespace pdb {
namespace error {
@@ -22,9 +24,13 @@ std::wstring trim_trailing_newline(const std::wstring& s) {
return s.substr(0, last_pos + 1);
}
-} // namespace
+std::string build_what(DWORD code, const char* function) {
+ std::ostringstream what;
+ what << "Function " << function << " failed with error code " << code;
+ return what.str();
+}
-std::string CategoryWindows::message(int code) const {
+std::string format_message(int code) {
wchar_t* buf;
const auto len = FormatMessageW(
@@ -46,5 +52,17 @@ std::string CategoryWindows::message(int code) const {
return boost::nowide::narrow(trim_trailing_newline(msg));
}
+} // namespace
+
+std::string CategoryWindows::message(int code) const {
+ return format_message(code);
+}
+
+std::system_error windows(DWORD code, const char* function) {
+ static_assert(sizeof(DWORD) == sizeof(int), "Aren't DWORDs the same size as ints?");
+ return std::system_error{
+ static_cast<int>(code), category_windows(), build_what(code, function)};
+}
+
} // namespace error
} // namespace pdb