-
-
Notifications
You must be signed in to change notification settings - Fork 392
Closed
Description
In regular Python, a catch-all exception handler looks like:
try:
...
except Exception as exc: # Don't catch KeyboardInterrupt, etc.
logger.error(..., exc_info=exc)In Trio we need to handle MultiErrors, which might contain a mix of exceptions we want to catch and ones we don't, etc. So you have to use MultiError.catch, and the above becomes:
def handler(exc):
if isinstance(exc, Exception):
logger.error(..., exc_info=exc)
return None # swallow this exception
else:
return exc # let other exceptions propagate
with MultiError.catch(handler):
...This is pointlessly cumbersome. We should make it look like this:
def handler(exc):
logger.error(..., exc_info=exc)
with MultiError.catch(Exception, handler): # Note the extra argument
...Reactions are currently unavailable