Title: finally block doesn't re-raise exception if return statement exists inside
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.4
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: David Rebbe, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-02-11 22:18 by David Rebbe, last changed 2018-02-11 23:19 by David Rebbe.

File name Uploaded Description Edit David Rebbe, 2018-02-11 22:18 shows exception handling differences in finally block
Messages (3)
msg312014 - (view) Author: David Rebbe (David Rebbe) Date: 2018-02-11 22:18
According to the docs:
"When an exception has occurred in the try clause and has not been handled by an except clause (or it has occurred in an except or else clause), it is re-raised after the finally clause has been executed."

This seems to not be the case if return inside a finally block, the exception needing to be thrown looks like its tossed out.

I'm not sure if this is intended behavior and the docs need to be updated or python isn't doing the correct behavior.

Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
msg312015 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-11 22:44
This is intended and documented behavior.
msg312017 - (view) Author: David Rebbe (David Rebbe) Date: 2018-02-11 23:19
Oops I didn't realize I referenced the tutorial documentation.

Maybe it would be better to mention this behavior in the tutorial documentation also.

I've always assumed exception raises take priority over any return/break/continues. Behavior is backwards from what I'd expect but makes sense.
Date User Action Args
2018-02-11 23:19:05David Rebbesetmessages: + msg312017
2018-02-11 22:44:33serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg312015
2018-02-11 22:18:17David Rebbecreate