b15f/driver/drv/timeoutexception.h

36 lines
700 B
C
Raw Normal View History

2019-03-29 10:12:31 +00:00
#ifndef TIMEOUTEXCEPTION_H
#define TIMEOUTEXCEPTION_H
#include <exception>
// SOURCE: https://stackoverflow.com/a/8152888
class TimeoutException: public std::exception
{
public:
explicit TimeoutException(const char* message, int timeout) : TimeoutException(std::string(message), timeout)
{
}
2019-04-05 08:38:59 +00:00
explicit TimeoutException(const std::string& message, int timeout) : msg(message), m_timeout(timeout)
2019-03-29 10:12:31 +00:00
{
if(!msg.length())
2019-04-05 08:38:59 +00:00
msg = "Timeout reached (" + std::to_string(m_timeout) + ")";
2019-03-29 10:12:31 +00:00
}
virtual ~TimeoutException() throw ()
{
}
virtual const char* what() const throw ()
{
return msg.c_str();
}
protected:
std::string msg;
2019-04-05 08:38:59 +00:00
int m_timeout;
2019-03-29 10:12:31 +00:00
};
#endif // TIMEOUTEXCEPTION_H