diff options
author | John Ankarström <john@ankarstrom.se> | 2022-09-03 15:28:56 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-09-03 15:28:56 +0200 |
commit | 6ae7e24675cff4ff6b808c3024f45083f35ced97 (patch) | |
tree | 2a47273f325d8367db2a8669691273f02ca83eb9 /c/win32.cpp | |
parent | 2cd22c671c67deaf2c1fcb659e3262bf57552557 (diff) | |
download | EpisodeBrowser-6ae7e24675cff4ff6b808c3024f45083f35ced97.tar.gz |
Improve error handling.
Diffstat (limited to 'c/win32.cpp')
-rw-r--r-- | c/win32.cpp | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/c/win32.cpp b/c/win32.cpp index 2686f2e..2ecea50 100644 --- a/c/win32.cpp +++ b/c/win32.cpp @@ -4,6 +4,7 @@ #include <windows.h> #include <wininet.h> +#include "err.h" #include "util.h" #include "win32.h" #include "window.h" @@ -16,7 +17,7 @@ std::wstring WideFromNarrow(const std::string_view src, const int cp) int cchWide = MultiByteToWideChar(cp, 0, src.data(), cchNarrow, nullptr, 0); std::wstring dst(cchWide, 0); if (!MultiByteToWideChar(cp, 0, src.data(), cchNarrow, dst.data(), cchWide)) - throw Win32Error(); + throw Err(WINDOWS, L"Narrow string could not be converted to wide string: %s"); return dst; } @@ -95,34 +96,6 @@ int EBMessageBox(const std::wstring_view text, const std::wstring_view caption, return MessageBox(hWnd, text.data(), caption.data(), uType); } -void Act(const wchar_t* action) -{ - s_action = action; -} - -void ShowException(const wchar_t* const fmt, const wchar_t* const title, const UINT uType) noexcept -{ - if (!s_action) - s_action = L"performing an unknown action"; - try { - std::rethrow_exception(std::current_exception()); - } catch (const WideException& e) { - std::wstring msg(wcslen(fmt)+wcslen(s_action)+wcslen(e.What()), 0); - Swprintf(msg, fmt, s_action, e.What()); - EBMessageBox(msg, title, uType); - } catch (const std::exception& e) { - std::wstring what = WideFromNarrow(e.what()); - std::wstring msg(wcslen(fmt)+wcslen(s_action)+what.length(), 0); - Swprintf(msg, fmt, s_action, what.c_str()); - EBMessageBox(msg, title, uType); - } catch (...) { - const wchar_t* what = L"an unknown error occurred"; - std::wstring msg(wcslen(fmt)+wcslen(s_action)+wcslen(what), 0); - Swprintf(msg, fmt, s_action, what); - EBMessageBox(msg, title, uType); - } -} - int GetRelativeCursorPos(const HWND hWnd, POINT* const pt) noexcept { RECT rc; @@ -229,7 +202,7 @@ Library::Library(const wchar_t* const lib) { m_hModule = LoadLibraryW(lib); if (!m_hModule) - throw Win32Error(); + throw Err(WINDOWS, L"Library "s + lib + L" could not be loaded: %s"); } Library::~Library() |