From b0ac4b5da2e98a0a1ada91cb5ba66ca2a3e17736 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Wed, 9 Sep 2015 14:56:38 -0600 Subject: [PATCH] adc121c021: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/adc121c021/adc121c021.cxx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/adc121c021/adc121c021.cxx b/src/adc121c021/adc121c021.cxx index 95567ccf..7bdb8a30 100644 --- a/src/adc121c021/adc121c021.cxx +++ b/src/adc121c021/adc121c021.cxx @@ -24,6 +24,7 @@ #include #include +#include #include "adc121c021.h" @@ -35,13 +36,23 @@ ADC121C021::ADC121C021(int bus, uint8_t address, float vref) { // setup our i2c link m_i2c = mraa_i2c_init(bus); + if ( !(m_i2c = mraa_i2c_init(bus)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_init() failed"); + return; + } m_addr = address; mraa_result_t ret = mraa_i2c_address(m_i2c, m_addr); - if (ret != MRAA_SUCCESS) - cerr << "ADC121C021: Could not initialize i2c bus. " << endl; + if (ret != MRAA_SUCCESS) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_i2c_address() failed"); + return; + } m_vref = vref; }