From af51973b2a77696d1e1646c768fde9db507121e8 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 3 Aug 2024 15:55:57 +0200 Subject: [PATCH] Added a variant of throwOnError that takes an additional error message. --- source/mijin/io/stream.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/mijin/io/stream.hpp b/source/mijin/io/stream.hpp index 1b7b0b8..4611706 100644 --- a/source/mijin/io/stream.hpp +++ b/source/mijin/io/stream.hpp @@ -11,6 +11,7 @@ #include #include #include "../container/typeless_buffer.hpp" +#include "../util/exception.hpp" namespace mijin { @@ -282,6 +283,14 @@ inline void throwOnError(mijin::StreamError error) } throw std::runtime_error(errorName(error)); } + +inline void throwOnError(mijin::StreamError error, std::string message) +{ + if (error == mijin::StreamError::SUCCESS) { + return; + } + throw std::runtime_error(message + ": " + errorName(error)); +} } // namespace mijin #endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)