From 1eb9e7b9dcc45e4741bd34351534af1e25bc9502 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Wed, 9 Sep 2015 15:48:28 -0600 Subject: [PATCH] apds9002: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/apds9002/apds9002.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/apds9002/apds9002.cxx b/src/apds9002/apds9002.cxx index 2e958cd5..1fe8be1f 100644 --- a/src/apds9002/apds9002.cxx +++ b/src/apds9002/apds9002.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include "apds9002.h" @@ -30,9 +32,13 @@ using namespace upm; APDS9002::APDS9002(int pin) { - mraa_init(); - - m_aio = mraa_aio_init(pin); + + if ( !(m_aio = mraa_aio_init(pin)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init() failed, invalid pin?"); + return; + } } APDS9002::~APDS9002()