I know this is a bad style to re-create an exception from the __exit__() context manager. Thus, I would like to apply an attribute to an instance that can carry contextual information that is not available if I allow the exception to leak or if I catch it. This will avoid raising it again.
An alternative to attaching an attribute to an exception would be to swallow the exception, set some state in the instance, which doubles as the context manager in question, and then check that state. The problem is that this will result in a catch of 22, right? Since an exception means that execution inside the with block completes. It is not possible to repeat the operation except re-entering the with block, right? Thus, the instance in which I am trying to save contextual information will disappear after the __exit__() method __exit__() .
In short: how can I manipulate the actual exception that expects (if any, which I will consider asked for this question), while in the __exit__() method?
0xC0000022L
source share