From: Jens Steinhauser Date: Tue, 7 Oct 2014 12:01:34 +0000 (+0200) Subject: bindings: Better error handling in enumeration get() function. X-Git-Tag: libsigrok-0.4.0~883 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=174bf146e5973cb7f11892c54972bc99e4a74eae;p=libsigrok.git 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. --- 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)); }} """