Added throwOnError utility function.

This commit is contained in:
Patrick 2024-07-23 20:16:24 +02:00
parent 83a46cae15
commit f35ee5f038

View File

@ -258,6 +258,30 @@ StreamError Stream::readAsString(std::basic_string<TChar>& outString)
return StreamError::SUCCESS;
}
inline const char* errorName(StreamError error) noexcept
{
switch (error)
{
case StreamError::SUCCESS:
return "success";
case StreamError::IO_ERROR:
return "IO error";
case StreamError::NOT_SUPPORTED:
return "not supported";
case StreamError::UNKNOWN_ERROR:
return "unknown error";
}
return "<invalid error>";
}
inline void throwOnError(mijin::StreamError error)
{
if (error == mijin::StreamError::SUCCESS) {
return;
}
throw std::runtime_error(errorName(error));
}
} // namespace mijin
#endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)