Skip to content

Finally clause can be canceled with CTRL + C #10457

@SeeminglyScience

Description

@SeeminglyScience

Steps to reproduce

try { } finally {
    Write-Host Press ctrl c now
    Start-Sleep 5
    Write-Host You`'ll never see this one
}

Evaluate the above script and press CTRL + C after the message is displayed.

Expected behavior

The entire finally block to complete.

Actual behavior

The finally block is cancelled when CTRL + C is pressed.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.3
PSEdition                      Core
GitCommitId                    7.0.0-preview.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This also occurs on Windows PowerShell 5.1

Notes

If CTRL + C is pressed in the try block, additional key presses in the finally block will be correctly ignored. e.g.

try {
    Write-Host Press ctrl c now
    Start-Sleep 5
} finally {
    Write-Host Try pressing it a bunch, won`'t do anything
    Start-Sleep 5
    Write-Host You`'ll actually see this one
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions