b15f/control/src/drv/timeoutexception.h

38 lines
797 B
C
Raw Normal View History

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