From 28b87e4d9c60b49d46b03a19b7b83e23e222087a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 22 Aug 2022 01:02:34 +0200 Subject: Handle exceptions in fetching thread. --- c/win.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'c/win.cpp') diff --git a/c/win.cpp b/c/win.cpp index 28dba27..ea47fb0 100644 --- a/c/win.cpp +++ b/c/win.cpp @@ -1,7 +1,33 @@ #include +#include #include +#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(why)); + EBMessageBox(msg, title, uType); +} void WithNextWindow(void (*proc)(HWND)) { -- cgit v1.2.3