You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
Sometimes after people catch an exception, they need to access attributes on it (e.g., OSError.errno).
But if you do with catch(OSError, handler): ..., then handler has to be prepared to get an ExceptionGroup, not an OSError. So how can handler access the errno attribute?
I guess the simplest possibility would be a global function accessor like:
defhandler(exc):
forleaf_excinexceptiongroup.leaf_exceptions(exc):
print(f"This exception's errno is {leaf_exc.errno}!")
(I don't think it will work to have a method on ExceptionGroup, or making ExceptionGroup iterable, because sometimes when you do with catch(OSError, handler): ... you get a plain OSError, with no ExceptionGroup wrapped around it. This is the same reason split is a function, not a method.)
The text was updated successfully, but these errors were encountered:
Sometimes after people catch an exception, they need to access attributes on it (e.g.,
OSError.errno
).But if you do
with catch(OSError, handler): ...
, thenhandler
has to be prepared to get anExceptionGroup
, not anOSError
. So how canhandler
access theerrno
attribute?I guess the simplest possibility would be a global function accessor like:
(I don't think it will work to have a method on
ExceptionGroup
, or makingExceptionGroup
iterable, because sometimes when you dowith catch(OSError, handler): ...
you get a plainOSError
, with noExceptionGroup
wrapped around it. This is the same reasonsplit
is a function, not a method.)The text was updated successfully, but these errors were encountered: