diff --git a/source/mijin/io/stream.hpp b/source/mijin/io/stream.hpp index 17e8515..f940716 100644 --- a/source/mijin/io/stream.hpp +++ b/source/mijin/io/stream.hpp @@ -469,6 +469,34 @@ inline void throwOnError(mijin::StreamError error, std::string message) } throw std::runtime_error(message + ": " + errorName(error)); } + +template +inline decltype(auto) throwOnError(StreamResult&& result) +{ + if (result.isError()) + { + throw Exception(errorName(result.getError())); + } + else if (!result.isSuccess()) + { + throw Exception("result is empty"); + } + return *result; +} + +template +inline decltype(auto) throwOnError(StreamResult&& result, const std::string& message) +{ + if (result.isError()) + { + throw Exception(message + ": " + errorName(result.getError())); + } + else if (!result.isSuccess()) + { + throw Exception(message + ": result is empty"); + } + return *result; +} } // namespace mijin #endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)