diff options
author | Brennan Ashton <bashton@brennanashton.com> | 2018-11-14 17:53:22 -0800 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-11-15 15:44:05 -0800 |
commit | 2f66412afaca4a42319c666958c89827edd8f2f3 (patch) | |
tree | f82482c09d4885fcd8b1a279484d5770767a32aa /gnuradio-runtime/python/gnuradio/eng_notation.py | |
parent | 39b74849d939456a0d1e4aa534e9f829e742ba63 (diff) |
gr-runtime: Improve exception handling in ControlPort Monitor
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/eng_notation.py')
-rw-r--r-- | gnuradio-runtime/python/gnuradio/eng_notation.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py index 391dc5838f..ec35b0db5b 100644 --- a/gnuradio-runtime/python/gnuradio/eng_notation.py +++ b/gnuradio-runtime/python/gnuradio/eng_notation.py @@ -23,6 +23,9 @@ Display numbers as strings using engineering notation. """ from __future__ import unicode_literals +import six + + scale_factor = {} scale_factor['E'] = 1e18 scale_factor['P'] = 1e15 @@ -66,11 +69,13 @@ def num_to_str (n, precision=6): def str_to_num (value): '''Convert a string in engineering notation to a number. E.g., '15m' -> 15e-3''' try: + if not isinstance(value, six.string_types): + raise TypeError("Value must be a string") scale = 1.0 suffix = value[-1] if suffix in scale_factor: return float (value[0:-1]) * scale_factor[suffix] return float (value) - except: - raise RuntimeError ( + except (TypeError, KeyError, ValueError): + raise ValueError ( "Invalid engineering notation value: %r" % (value,)) |