aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/error.cpp
diff options
context:
space:
mode:
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