From 6ae7e24675cff4ff6b808c3024f45083f35ced97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 3 Sep 2022 15:28:56 +0200 Subject: Improve error handling. --- c/util.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'c/util.h') diff --git a/c/util.h b/c/util.h index da77ff9..668d040 100644 --- a/c/util.h +++ b/c/util.h @@ -1,10 +1,12 @@ #ifndef UTIL_H #define UTIL_H +#include #include #include #include #include +#include #include #define CONCAT_IMPL(a, b) a##b @@ -14,9 +16,7 @@ #define SET_TERMINATE \ std::set_terminate([]() noexcept \ { \ - ShowException( \ - L"Episode Browser was terminated due to an error while %s: %s", \ - L"Fatal Error", MB_ICONERROR); \ + EBMessageBox(What(), L"Fatal Error", MB_ICONERROR); \ _Exit(1); \ }) @@ -98,14 +98,12 @@ struct UniqueOk T v; UniqueOk(Unique&& u) : v(std::move(u.v)) { - if (!u.ok) - throw std::runtime_error("cannot construct UniqueOk from non-ok Unique"); + assert(u.ok, "UniqueOk may not be constructed from non-ok Unique"); u.ok = false; } UniqueOk& operator =(Unique&& u) { - if (!u.ok) - throw std::runtime_error("cannot construct UniqueOk from non-ok Unique"); + assert(u.ok, "UniqueOk may not be constructed from non-ok Unique"); F(v); v = std::move(u.v); u.ok = false; @@ -153,14 +151,16 @@ inline size_t Len(T (&)[N]) /* Format wide string. */ template -inline int Swprintf(Buf buf, const wchar_t* const fmt, T... xs) +inline std::enable_if_t...>, int> +Swprintf(Buf buf, const wchar_t* const fmt, T... xs) { return _snwprintf_s(buf, buf.c, _TRUNCATE, fmt, xs...); } /* Format static narrow string. */ template -inline int Sprintf(Buf buf, const char* const fmt, T... xs) +inline std::enable_if_t...>, int> +Sprintf(Buf buf, const char* const fmt, T... xs) { return _snprintf_s(buf, buf.c, _TRUNCATE, fmt, xs...); } -- cgit v1.2.3