diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-22 01:02:34 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-22 01:02:34 +0200 |
commit | 28b87e4d9c60b49d46b03a19b7b83e23e222087a (patch) | |
tree | 1f0a71ca09f04eac51fdabf2e8cfabc87a6e02a3 /c/win.cpp | |
parent | 801c10f07d1c92e1b1b89d8a30cb0cf86745de31 (diff) | |
download | EpisodeBrowser-28b87e4d9c60b49d46b03a19b7b83e23e222087a.tar.gz |
Handle exceptions in fetching thread.
Diffstat (limited to 'c/win.cpp')
-rw-r--r-- | c/win.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1,7 +1,33 @@ #include <utility> +#include <SWI-Prolog.h> #include <windows.h> +#include "pl.h" +#include "util.h" #include "win.h" +#include "wcharptr.h" + +void ShowException(const wchar_t* const fmt, const wchar_t* const title, const UINT uType) noexcept +{ + const wchar_t* what = L"an exception"; + WcharPtr why; + + try { + std::rethrow_exception(std::current_exception()); + } catch (const term_t& t) { + what = L"a Prolog exception"; + try { why = PlString(t); } catch (...) {} + } catch (const Win32Error& e) { + what = L"a Windows error"; + try { why = WcharPtr::Copy(e.What()); } catch (...) {} + } catch (const std::exception& e) { + try { why = WcharPtr::FromNarrow(e.what()); } catch (...) {} + } catch (...) {} + + wchar_t msg[512]; + Swprintf(msg, fmt, what, static_cast<wchar_t*>(why)); + EBMessageBox(msg, title, uType); +} void WithNextWindow(void (*proc)(HWND)) { |