diff options
author | 2023-06-09 11:10:34 +0200 | |
---|---|---|
committer | 2023-06-09 13:40:38 -0500 | |
commit | 1415cc1ebb6e36112828210bb307ba682e5f81d9 (patch) | |
tree | e964be1162c79ac5121030b191a22226310ab1b6 /mpm | |
parent | fpga: lib: Fix Vivado warnings (diff) | |
download | uhd-1415cc1ebb6e36112828210bb307ba682e5f81d9.tar.xz uhd-1415cc1ebb6e36112828210bb307ba682e5f81d9.zip |
mpm: Add LogRuntimeError class
This inherits RuntimeError and saves from logging and throwing in
separate steps. Instead of
```python
log.error("Error X occured!")
raise RuntimeError("Error X occured!")
```
do
```python
raise LogRuntimeError(log, "Error X occured!")
```
Diffstat (limited to 'mpm')
-rw-r--r-- | mpm/python/usrp_mpm/mpmutils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/mpmutils.py b/mpm/python/usrp_mpm/mpmutils.py index 861f8ac49..1f7bd7107 100644 --- a/mpm/python/usrp_mpm/mpmutils.py +++ b/mpm/python/usrp_mpm/mpmutils.py @@ -317,3 +317,13 @@ class LogWrapper: """ return getattr(self._wc, k) # pylint: enable=too-few-public-methods + + +class LogRuntimeError(RuntimeError): + """ + Custom version of RuntimeError that also prints the exception message to + a logger. + """ + def __init__(self, log, message): + log.error(message) + super.__init__(message) |