Added a variant of throwOnError that takes an additional error message.

This commit is contained in:
Patrick 2024-08-03 15:55:57 +02:00
parent 686dff506d
commit af51973b2a

View File

@ -11,6 +11,7 @@
#include <span> #include <span>
#include <string> #include <string>
#include "../container/typeless_buffer.hpp" #include "../container/typeless_buffer.hpp"
#include "../util/exception.hpp"
namespace mijin namespace mijin
{ {
@ -282,6 +283,14 @@ inline void throwOnError(mijin::StreamError error)
} }
throw std::runtime_error(errorName(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 } // namespace mijin
#endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED) #endif // !defined(MIJIN_IO_STREAM_HPP_INCLUDED)