From 174bf146e5973cb7f11892c54972bc99e4a74eae Mon Sep 17 00:00:00 2001 From: Jens Steinhauser Date: Tue, 7 Oct 2014 14:01:34 +0200 Subject: [PATCH] bindings: Better error handling in enumeration get() function. Prior to this patch a call to get() with an invalid enumeration value would raise an exception that would, for example, terminate the python interpreter, whereas now the exception is handled and translated into a proper python exception. --- bindings/cxx/enums.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bindings/cxx/enums.py b/bindings/cxx/enums.py index e942058c..9eddd1ad 100644 --- a/bindings/cxx/enums.py +++ b/bindings/cxx/enums.py @@ -95,6 +95,9 @@ code_template = """ const {classname} *{classname}::get(int id) {{ + if (_values.find(static_cast<{enumname}>(id)) == _values.end()) + throw Error(SR_ERR_ARG); + return {classname}::_values.at(static_cast<{enumname}>(id)); }} """