PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
43.55k stars 7.06k forks source link

[Regression in 7.4.2] Statement in finally block stop working when ctrl-c is pressed that stops script running in the try block #21552

Open daxian-dbw opened 2 weeks ago

daxian-dbw commented 2 weeks ago

Prerequisites

Steps to reproduce

Remove-Item -ErrorAction Ignore temp:/$PID.txt
try {
  Read-Host 'Press Ctrl-C now'
}
finally {
  ## this should be put in the file
  "Hello" > temp:/$PID.txt  ## or Get-Date > temp:/$PID.txt
}

## Press ctrl+c, then run
cat temp:/$PID.txt

Expected behavior

## "Hello" should be printed, which is the behavior in 7.2, 7.4.0, and 7.4.1.
Hello

Actual behavior

This is a regression in 7.4.2

Nothing is written out. The file doesn't contain any content.

Error details

No Error.

Environment data

PS:38> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response