From bea94a70b296b7781c0ca7604e03811c353b77ec Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Wed, 9 Sep 2015 11:49:00 -0600 Subject: [PATCH] uln200xa: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/uln200xa/uln200xa.cxx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/uln200xa/uln200xa.cxx b/src/uln200xa/uln200xa.cxx index cd03ede0..068c7665 100644 --- a/src/uln200xa/uln200xa.cxx +++ b/src/uln200xa/uln200xa.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include "uln200xa.h" @@ -38,14 +40,16 @@ ULN200XA::ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4) if ( !(m_stepI1 = mraa_gpio_init(i1)) ) { - cerr << __FUNCTION__ << ": mraa_gpio_init(i1) failed" << endl; + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(i1) failed, invalid pin?"); return; } mraa_gpio_dir(m_stepI1, MRAA_GPIO_OUT); if ( !(m_stepI2 = mraa_gpio_init(i2)) ) { - cerr << __FUNCTION__ << ": mraa_gpio_init(i2) failed" << endl; + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(i2) failed, invalid pin?"); mraa_gpio_close(m_stepI1); return; } @@ -53,7 +57,8 @@ ULN200XA::ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4) if ( !(m_stepI3 = mraa_gpio_init(i3)) ) { - cerr << __FUNCTION__ << ": mraa_gpio_init(i3) failed" << endl; + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(i3) failed, invalid pin?"); mraa_gpio_close(m_stepI1); mraa_gpio_close(m_stepI2); return; @@ -62,7 +67,8 @@ ULN200XA::ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4) if ( !(m_stepI4 = mraa_gpio_init(i4)) ) { - cerr << __FUNCTION__ << ": mraa_gpio_init(i4) failed" << endl; + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_gpio_init(i4) failed, invalid pin?"); mraa_gpio_close(m_stepI1); mraa_gpio_close(m_stepI2); mraa_gpio_close(m_stepI3);