diff --git a/src/max5487/max5487.cxx b/src/max5487/max5487.cxx index 44c917c6..23c5d8c7 100644 --- a/src/max5487/max5487.cxx +++ b/src/max5487/max5487.cxx @@ -25,18 +25,12 @@ #include #include #include +#include #include "max5487.h" using namespace upm; -struct MAX5487Exception : public std::exception { - std::string message; - MAX5487Exception (std::string msg) : message (msg) { } - ~MAX5487Exception () throw () { } - const char* what() const throw () { return message.c_str(); } -}; - MAX5487::MAX5487 (int csn) { mraa_result_t error = MRAA_SUCCESS; m_name = "MAX5487"; @@ -45,18 +39,21 @@ MAX5487::MAX5487 (int csn) { if (csn != -1) { m_csnPinCtx = mraa_gpio_init (csn); if (m_csnPinCtx == NULL) { - throw MAX5487Exception ("GPIO failed to initilize"); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init() failed"); } error = mraa_gpio_dir (m_csnPinCtx, MRAA_GPIO_OUT); if (error != MRAA_SUCCESS) { - throw MAX5487Exception ("GPIO failed to initilize"); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_dir() failed"); } } m_spi = mraa_spi_init (0); if (m_spi == NULL) { - throw MAX5487Exception ("SPI failed to initilize"); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_spi_init() failed"); } CSOff ();