epy.reraise#
- etils.epy.reraise(e: Exception, prefix: str | Callable[[], str] | None = None, suffix: str | Callable[[], str] | None = None) NoReturn [source]#
Reraise an exception with an additional message.
Benefit: Contrary to raise … from … and raise Exception().with_traceback(tb), this function will:
Keep the original exception type, attributes,…
Avoid multi-nested During handling of the above exception, another exception occurred. Only the single original stacktrace is displayed.
This result in cleaner and more compact error messages.
Usage:
try: fn(x) except Exception as e: epy.reraise(e, prefix=f'Error for {x}: ')
- Parameters:
e – Exception to reraise
prefix – Prefix to add to the exception message.
suffix – Suffix to add to the exception message.