From 2f2b502813015732e78bfa2413f4673d855f8eaf Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Wed, 9 Sep 2015 11:06:01 -0600 Subject: [PATCH] joystick12: throw exception(s) on fatal errors Signed-off-by: Jon Trulson Signed-off-by: Mihai Tudor Panu --- src/joystick12/joystick12.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/joystick12/joystick12.cxx b/src/joystick12/joystick12.cxx index 4e8f2455..b70557ca 100644 --- a/src/joystick12/joystick12.cxx +++ b/src/joystick12/joystick12.cxx @@ -23,6 +23,8 @@ */ #include +#include +#include #include #include #include @@ -42,9 +44,20 @@ const int Joystick12::Y_right= 4070; Joystick12::Joystick12(int pinX, int pinY) { - mraa_result_t error; - m_joystickCtxX = mraa_aio_init(pinX); - m_joystickCtxY = mraa_aio_init(pinY); + + if ( !(m_joystickCtxX = mraa_aio_init(pinX)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init(pinX) failed, invalid pin?"); + return; + } + + if ( !(m_joystickCtxY = mraa_aio_init(pinY)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_aio_init(pinY) failed, invalid pin?"); + return; + } } Joystick12::~Joystick12() {