aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/main.cpp')
-rw-r--r--c/main.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/c/main.cpp b/c/main.cpp
index 144d151..7af5a0b 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -44,32 +44,30 @@ static void WaitFor(const char*, const char*);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static void UpdateTheme();
-void TerminateMsg(const wchar_t* wsz1, const wchar_t* wsz2) noexcept
-{
- wchar_t wsz[256] = {0};
- if (wsz2)
- wszf(wsz, L"Episode Browser was terminated due to %s: %s", wsz1, wsz2);
- else
- wszf(wsz, L"Episode Browser was terminated due to %s.", wsz1);
- MessageBox(g_hWnd, wsz, L"Fatal Error", MB_ICONERROR);
-}
-
void OnTerminate() noexcept
{
+ const wchar_t* wszWhat = L"an exception";
+ wstring_owner wsoWhy;
+
try {
std::rethrow_exception(std::current_exception());
} catch (const term_t& t) {
- if (auto wso = PlString(t))
- TerminateMsg(L"a Prolog exception", wso.p);
- else
- TerminateMsg(L"a Prolog exception", NULL);
+ wszWhat = L"a Prolog exception";
+ try { wsoWhy = PlString(t); } catch (...) {}
} catch (const Win32Error& e) {
- TerminateMsg(L"a Windows error", e.WhatW());
+ wszWhat = L"a Windows error";
+ try { wsoWhy = WsoCopy(e.WhatW()); } catch (...) {}
} catch (const std::exception& e) {
- TerminateMsg(L"an exception", WsoFromSz(e.what()).p);
- } catch (...) {
- TerminateMsg(L"an exception", NULL);
- }
+ try { wsoWhy = WsoFromSz(e.what()); } catch (...) {}
+ } catch (...) {}
+
+ wchar_t wsz[256] = {0};
+ if (wsoWhy)
+ wszf(wsz, L"Episode Browser was terminated due to %s: %s", wszWhat, wsoWhy.p);
+ else
+ wszf(wsz, L"Episode Browser was terminated due to %s.", wszWhat);
+
+ MessageBox(g_hWnd, wsz, L"Fatal Error", MB_ICONERROR);
_Exit(1);
}