Added throwOnError() for StreamResults.
This commit is contained in:
parent
c4e3576bc7
commit
161fdb6c93
@ -469,6 +469,34 @@ inline void throwOnError(mijin::StreamError error, std::string message)
|
||||
}
|
||||
throw std::runtime_error(message + ": " + errorName(error));
|
||||
}
|
||||
|
||||
template<typename TSuccess>
|
||||
inline decltype(auto) throwOnError(StreamResult<TSuccess>&& result)
|
||||
{
|
||||
if (result.isError())
|
||||
{
|
||||
throw Exception(errorName(result.getError()));
|
||||
}
|
||||
else if (!result.isSuccess())
|
||||
{
|
||||
throw Exception("result is empty");
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
|
||||
template<typename TSuccess>
|
||||
inline decltype(auto) throwOnError(StreamResult<TSuccess>&& 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user