Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

New API for handling concurrent exceptions #1683

Copy link
Copy link
Closed
@bob1de

Description

@bob1de
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.