Added throwOnError utility function.
This commit is contained in:
parent
83a46cae15
commit
f35ee5f038
@ -258,6 +258,30 @@ StreamError Stream::readAsString(std::basic_string<TChar>& outString)
|
|||||||
return StreamError::SUCCESS;
|
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
|
} // namespace mijin
|
||||||
|
|
||||||
#endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)
|
#endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user