1
0
Fork 0

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.
This commit is contained in:
Florent Rougon 2019-04-30 08:03:54 +02:00
parent babf0ded0c
commit a5792617f7

View file

@ -27,10 +27,11 @@
#include <Windows.h> #include <Windows.h>
#include <cassert>
#include <cstring> #include <cstring>
#include <RegStr.h> // for REGSTR_PATH_JOYCONFIG, etc #include <RegStr.h> // for REGSTR_PATH_JOYCONFIG, etc
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#define _JS_MAX_AXES_WIN 8 /* X,Y,Z,R,U,V,POV_X,POV_Y */ #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: case JOYERR_NOERROR:
return "no error"; return "no error";
default: 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 // Inspired by