I currently have code that looks like this scatterred throughout my codebase:
try:
something()
catch Exception as exc:
raise SomethingError from exc
I would like to write a context manager that would remove some of this boiler-plate:
with ExceptionWrapper(SomethingError):
something()
It looks like it is possible to suppress exceptions inside a context manager – see: contextlib.suprress
(https://docs.python.org/3/library/contextlib.html#contextlib.suppress). It doesn’t look like it is possible to change what exception is being raised.
However, I haven’t been able to find clear documentation on what the return value of the __exit__
function of a context manager is.