From e217a93d59aecfa80eec8bfa16b3976abdceca81 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 19 Dec 2014 14:05:47 +0200 Subject: [PATCH] Add a dedicated exception class for unavailable input devices --- source/input/device.h | 9 +++++++++ source/input/generic/gamecontroller.cpp | 2 +- source/input/touchscreen.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/input/device.h b/source/input/device.h index 7df388b..b42ed3f 100644 --- a/source/input/device.h +++ b/source/input/device.h @@ -3,11 +3,20 @@ #include #include +#include #include namespace Msp { namespace Input { +class device_not_available: public std::runtime_error +{ +public: + device_not_available(const std::string &w): std::runtime_error(w) { } + virtual ~device_not_available() throw() { } +}; + + /** Base class for input devices. Input devices have two types of controls: buttons and axes. Buttons are either on or off. Axes have a floating point diff --git a/source/input/generic/gamecontroller.cpp b/source/input/generic/gamecontroller.cpp index b320342..9ba7130 100644 --- a/source/input/generic/gamecontroller.cpp +++ b/source/input/generic/gamecontroller.cpp @@ -8,7 +8,7 @@ namespace Input { GameController::GameController(unsigned) { - throw runtime_error("not supported"); + throw device_not_available("GameController"); } GameController::~GameController() diff --git a/source/input/touchscreen.cpp b/source/input/touchscreen.cpp index 4facb8c..c4de688 100644 --- a/source/input/touchscreen.cpp +++ b/source/input/touchscreen.cpp @@ -9,7 +9,7 @@ Touchscreen::Touchscreen(Graphics::Window &w): window(w) { if(!is_available()) - throw runtime_error("touchscreen not available"); + throw device_not_available("Touchscreen"); name = "Touchscreen"; -- 2.43.0