-
-
Notifications
You must be signed in to change notification settings - Fork 374
Description
Hi,
I wasn't sure whether this should go into the exceptiongroup repo or not, so I'm opening the issue here because I implemented and use this with MultiError in current trio. However, it can be ported to ExceptionGroup easily.
I needed to catch concurrent exceptions at various places and found it quite unergonomic to use MultiError.catch the way handlers need to be implemented right now.
So I thought back and forth about it and came up with a context manager-based approach where the code inside the context is guarded by exception handling and handlers for individual exceptions can be registered using decorators. Both sync and async handlers are supported, and it also allows registering handlers for the else and finally branches so that one can avoid another try block + the extra indentation.
The code can be found here:
https://github.com/efficiosoft/trio_catcher
Docs and some thoughts are provided in README and docstrings.
I'd be very interested in what you think about such an approach. Imho, at least it's the cleanest-looking I've found so far. :-)
Best regards
Robert