diff options
author | John Ankarström <john@ankarstrom.se> | 2022-09-03 15:28:56 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-09-03 15:28:56 +0200 |
commit | 6ae7e24675cff4ff6b808c3024f45083f35ced97 (patch) | |
tree | 2a47273f325d8367db2a8669691273f02ca83eb9 /c/util.h | |
parent | 2cd22c671c67deaf2c1fcb659e3262bf57552557 (diff) | |
download | EpisodeBrowser-6ae7e24675cff4ff6b808c3024f45083f35ced97.tar.gz |
Improve error handling.
Diffstat (limited to 'c/util.h')
-rw-r--r-- | c/util.h | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,10 +1,12 @@ #ifndef UTIL_H #define UTIL_H +#include <cassert> #include <cstring> #include <memory> #include <stdexcept> #include <string> +#include <type_traits> #include <windows.h> #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<T, F>&& 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<T, F>&& 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<typename... T> -inline int Swprintf(Buf<wchar_t> buf, const wchar_t* const fmt, T... xs) +inline std::enable_if_t<!std::disjunction_v<std::is_class<T>...>, int> +Swprintf(Buf<wchar_t> buf, const wchar_t* const fmt, T... xs) { return _snwprintf_s(buf, buf.c, _TRUNCATE, fmt, xs...); } /* Format static narrow string. */ template<typename... T> -inline int Sprintf(Buf<char> buf, const char* const fmt, T... xs) +inline std::enable_if_t<!std::disjunction_v<std::is_class<T>...>, int> +Sprintf(Buf<char> buf, const char* const fmt, T... xs) { return _snprintf_s(buf, buf.c, _TRUNCATE, fmt, xs...); } |