[Python-Dev] Handle errors in cleanup code (original) (raw)
Stefan Ring stefanrin at gmail.com
Tue Jun 13 04:32:48 EDT 2017
- Previous message (by thread): [Python-Dev] Handle errors in cleanup code
- Next message (by thread): [Python-Dev] PEP 538 warning at startup: please remove it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jun 13, 2017 at 2:26 AM, Nathaniel Smith <njs at pobox.com> wrote:
On Mon, Jun 12, 2017 at 6:29 AM, Stefan Ring <stefanrin at gmail.com> wrote:
> Yury in the comment for PR 2108 [1] suggested more complicated code: > > dosomething() > try: > dosomethingother() > except BaseException as ex: > try: > undosomething() > finally: > raise ex And this is still bad, because it loses the back trace. The way we do it is: dosomething() try: dosomethingother() except BaseException as ex: tb = sys.excinfo()[2] try: undosomething() finally: raise ex, None, tb Are you testing on python 2? On Python 3 just plain 'raise ex' seems to give a sensible traceback for me...
Yes, on Python 2.
Interesting to know that this has changed in Python 3. I'll check this out immediately.
- Previous message (by thread): [Python-Dev] Handle errors in cleanup code
- Next message (by thread): [Python-Dev] PEP 538 warning at startup: please remove it
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]