[Python-Dev] Handle errors in cleanup code
Stefan Ring
stefanrin at gmail.com
Mon Jun 12 09:29:00 EDT 2017
More information about the Python-Dev mailing list
Mon Jun 12 09:29:00 EDT 2017
- Previous message (by thread): [Python-Dev] Handle errors in cleanup code
- Next message (by thread): [Python-Dev] Handle errors in cleanup code
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Yury in the comment for PR 2108 [1] suggested more complicated code:
>
> do_something()
> try:
> do_something_other()
> except BaseException as ex:
> try:
> undo_something()
> finally:
> raise ex
And this is still bad, because it loses the back trace. The way we do it is:
do_something()
try:
do_something_other()
except BaseException as ex:
tb = sys.exc_info()[2]
try:
undo_something()
finally:
raise ex, None, tb
- Previous message (by thread): [Python-Dev] Handle errors in cleanup code
- Next message (by thread): [Python-Dev] Handle errors in cleanup code
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list