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, 21 insertions, 15 deletions
diff --git a/c/main.cpp b/c/main.cpp
index c426c65..4f31e7b 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -1,4 +1,5 @@
#include <exception>
+#include <sstream>
#include <windows.h>
#include <commctrl.h>
#include <uxtheme.h>
@@ -46,30 +47,35 @@ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static void UpdateTheme();
+template <typename T>
+void TerminateMsg(const T* sz1, const T* sz2) noexcept
+{
+ std::basic_ostringstream<T> ss;
+ ss << AWTEXT(T, "Episode Browser was terminated due to ");
+ ss << sz1;
+ if (sz2)
+ ss << ": " << sz2;
+ else
+ ss << ".";
+ AWFUN(T, MessageBox)((HWND)NULL, ss.str().c_str(), AWTEXT(T, "Fatal Error"), MB_ICONERROR);
+}
+
void OnTerminate() noexcept
{
try {
std::rethrow_exception(std::current_exception());
} catch (const term_t& t) {
- std::basic_string<TCHAR> tstr = TEXT("Episode Browser was terminated due to a Prolog exception: ");
TCHAR* tsz;
- if (PL_get_tchars(t, &tsz, CVT_WRITE)) {
- tstr += tsz;
- MessageBox(NULL, tstr.c_str(), TEXT("Fatal Error"), MB_ICONERROR);
- } else
- MessageBoxA(NULL, "Episode Browser was terminated due to a Prolog exception.",
- "Fatal Error", MB_ICONERROR);
+ if (PL_get_tchars(t, &tsz, CVT_WRITE))
+ TerminateMsg<TCHAR>(TEXT("a Prolog exception"), tsz);
+ else
+ TerminateMsg<char>("a Prolog exception", NULL);
} catch (Win32Error& e) {
- std::basic_string<TCHAR> tstr = TEXT("Episode Browser was terminated due to a Windows error: ");
- tstr += e.what<TCHAR>();
- MessageBox(NULL, tstr.c_str(), TEXT("Fatal Error"), MB_ICONERROR);
+ TerminateMsg<TCHAR>(TEXT("a Windows error"), e.what<TCHAR>());
} catch (std::exception& e) {
- std::string str = "Episode Browser was terminated due to an exception: ";
- str += e.what();
- MessageBoxA(NULL, str.c_str(), "Fatal Error", MB_ICONERROR);
+ TerminateMsg<char>("an exception", e.what());
} catch (...) {
- MessageBoxA(NULL, "Episode Browser was terminated due to an exception.",
- "Fatal Error", MB_ICONERROR);
+ TerminateMsg<char>("an exception", NULL);
}
_Exit(1);
}