This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improper behaviour of 'finally' keyword
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Priyanshu, paul.moore, ronaldoussoren, serhiy.storchaka, steve.dower, steven.daprano, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-07-27 06:49 by Priyanshu, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
error.py Priyanshu, 2021-07-27 12:29
error.py - Visual Studio Code 27_07_2021 6_50_36 PM.png Priyanshu, 2021-07-27 13:24
Messages (9)
msg398278 - (view) Author: Priyanshu (Priyanshu) Date: 2021-07-27 06:49
The finally clause is not executed when an exception occurs and 'raise' keyword is used in except clause.
msg398279 - (view) Author: Priyanshu (Priyanshu) Date: 2021-07-27 06:51
The 'finally' clause is not executed when an exception occurs and 'raise' keyword is used in except clause.
msg398281 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-27 07:08
I cannot reproduce.

>>> try:
...     1/0
... except:
...     print('except')
...     raise
... finally:
...     print('finally')
... 
except
finally
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

Could you please provide an example code?
msg398293 - (view) Author: Priyanshu (Priyanshu) Date: 2021-07-27 12:29
I have attached a file as an example. The finally clause is not getting executed if we make use of raise keyword in except clause. It should have been executed in this case case, right?
msg398294 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2021-07-27 12:52
It works as expected (the print statement in the "finally" clause is executed) for me.
msg398296 - (view) Author: Priyanshu (Priyanshu) Date: 2021-07-27 13:24
Really? Why is it not working for me then? I am using the latest version of
VS code application. I have attached a screenshot,have a look at this.

On Tue, Jul 27, 2021 at 6:22 PM Paul Moore <report@bugs.python.org> wrote:

>
> Paul Moore <p.f.moore@gmail.com> added the comment:
>
> It works as expected (the print statement in the "finally" clause is
> executed) for me.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44746>
> _______________________________________
>
msg398297 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2021-07-27 13:39
The output from the print statement in the finally block is before the traceback, you need to scroll back in the output buffer in VS Code.
msg398302 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-07-27 15:06
Confirmed that it is working in Linux. I assume Paul has tested it under Windows, and it sounds like Ronald has tested it in VS Code as well.

I'm closing this as Not A Bug.

Priyanshu, if you disagree and can replicate the error, this time checking the output buffer, please reply with a new example.
msg398306 - (view) Author: Priyanshu (Priyanshu) Date: 2021-07-27 15:48
Ok, I'll check it out.
Thank you for the response.

On Tue, 27 Jul, 2021, 20:36 Steven D'Aprano, <report@bugs.python.org> wrote:

>
> Steven D'Aprano <steve+python@pearwood.info> added the comment:
>
> Confirmed that it is working in Linux. I assume Paul has tested it under
> Windows, and it sounds like Ronald has tested it in VS Code as well.
>
> I'm closing this as Not A Bug.
>
> Priyanshu, if you disagree and can replicate the error, this time checking
> the output buffer, please reply with a new example.
>
> ----------
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue44746>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88909
2021-07-27 15:48:02Priyanshusetmessages: + msg398306
2021-07-27 15:06:36steven.dapranosetstatus: open -> closed
resolution: not a bug
messages: + msg398302

stage: resolved
2021-07-27 13:39:16ronaldoussorensetnosy: + ronaldoussoren
messages: + msg398297
2021-07-27 13:24:49Priyanshusetfiles: + error.py - Visual Studio Code 27_07_2021 6_50_36 PM.png

messages: + msg398296
2021-07-27 12:52:26paul.mooresetmessages: + msg398294
2021-07-27 12:29:49Priyanshusetfiles: + error.py

messages: + msg398293
2021-07-27 07:23:35steven.dapranosetnosy: + steven.daprano
2021-07-27 07:08:48serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg398281
2021-07-27 06:51:23Priyanshusetmessages: + msg398279
2021-07-27 06:49:22Priyanshucreate