From a5792617f7c6c55580b11ed7e512d1b25aa0ba8d Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Tue, 30 Apr 2019 08:03:54 +0200 Subject: [PATCH] jsWindows: throw exception instead of using an assert Since asserts can be compiled as no-ops, throw an exception rather than doing assert(false), in case the code passed to joyGetDevCaps_errorString() is not one of the expected values. --- 3rdparty/joystick/jsWindows.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/3rdparty/joystick/jsWindows.cxx b/3rdparty/joystick/jsWindows.cxx index dc304a599..d705e3474 100644 --- a/3rdparty/joystick/jsWindows.cxx +++ b/3rdparty/joystick/jsWindows.cxx @@ -27,10 +27,11 @@ #include -#include #include #include // for REGSTR_PATH_JOYCONFIG, etc + #include +#include #define _JS_MAX_AXES_WIN 8 /* X,Y,Z,R,U,V,POV_X,POV_Y */ @@ -53,10 +54,14 @@ static std::string joyGetDevCaps_errorString(MMRESULT errorCode) case JOYERR_NOERROR: return "no error"; default: - assert(false); + throw sg_exception( + "Unexpected value passed to joyGetDevCaps_errorString(): " + + std::to_string(errorCode)); } - return "bug: the program should not get here"; + throw sg_exception("This code path should be unreachable; value " + "passed to joyGetDevCaps_errorString(): " + + std::to_string(errorCode)); } // Inspired by