b15f/control/src/drv/usartexception.h

47 lines
862 B
C
Raw Normal View History

2019-03-29 11:12:31 +01:00
#ifndef USARTEXCEPTION_H
#define USARTEXCEPTION_H
#include <exception>
#include <string>
2019-05-23 15:08:54 +02:00
/*! Exception for USART problems, for instance buffer overflow. */
2019-03-29 11:12:31 +01:00
class USARTException: public std::exception
{
public:
2019-06-04 10:00:41 +02:00
/**
* Constructor
* @param message as c-string
*/
2019-05-23 15:08:54 +02:00
explicit USARTException(const char* message) : msg(message)
{
}
2019-03-29 11:12:31 +01:00
2019-06-04 10:00:41 +02:00
/**
* Constructor
* @param message as c++-string
*/
2019-05-23 15:08:54 +02:00
explicit USARTException(const std::string& message) : msg(message)
{
}
2019-03-29 11:12:31 +01:00
2019-06-04 10:00:41 +02:00
/**
* Standard-destructor
*/
virtual ~USARTException() = default;
2019-03-29 11:12:31 +01:00
2019-06-04 10:00:41 +02:00
/**
* Get failure description
* @return error message as c-string
*/
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-06-04 10:00:41 +02:00
std::string msg; //!< failure description
2019-03-29 11:12:31 +01:00
};
#endif // USARTEXCEPTION_H