From 984391eb64b199afddf56b7a719c096ca3349b49 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 7 Aug 2015 16:43:01 -0600 Subject: [PATCH] sm130: remove custom exception and use standard ones Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/sm130/sm130.cxx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/sm130/sm130.cxx b/src/sm130/sm130.cxx index 2bb48bb3..eaf89d0c 100644 --- a/src/sm130/sm130.cxx +++ b/src/sm130/sm130.cxx @@ -27,18 +27,12 @@ #include #include #include +#include #include "sm130.h" using namespace upm; -struct SM130Exception : public std::exception { - std::string message; - SM130Exception (std::string msg) : message (msg) { } - ~SM130Exception () throw () { } - const char* what() const throw () { return message.c_str(); } -}; - SM130::SM130 (int bus, int devAddr, int rst, int dready) { mraa_result_t error = MRAA_SUCCESS; @@ -47,31 +41,40 @@ SM130::SM130 (int bus, int devAddr, int rst, int dready) { this->m_i2cAddr = devAddr; this->m_bus = bus; - this->m_i2Ctx = mraa_i2c_init(this->m_bus); + if (!(m_i2Ctx = mraa_i2c_init(m_bus))) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_init() failed"); + } mraa_result_t ret = mraa_i2c_address(this->m_i2Ctx, this->m_i2cAddr); if (ret != MRAA_SUCCESS) { - throw SM130Exception ("Couldn't initilize I2C."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_address() failed"); } this->m_resetPinCtx = mraa_gpio_init (rst); if (m_resetPinCtx == NULL) { - throw SM130Exception ("Couldn't initilize RESET pin."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(RESET) failed"); } this->m_dataReadyPinCtx = mraa_gpio_init (dready); if (m_dataReadyPinCtx == NULL) { - throw SM130Exception ("Couldn't initilize DATA READY pin."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(DATA READY) failed"); } error = mraa_gpio_dir (this->m_resetPinCtx, MRAA_GPIO_OUT); if (error != MRAA_SUCCESS) { - throw SM130Exception ("Couldn't set direction for RESET pin."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_dir(RESET) failed"); } error = mraa_gpio_dir (this->m_dataReadyPinCtx, MRAA_GPIO_OUT); if (error != MRAA_SUCCESS) { - throw SM130Exception ("Couldn't set direction for DATA READY pin."); + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_dir(DATA READY) failed"); } }