question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Finally clause can be canceled with CTRL + C

See original GitHub issue

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 <kbd>CTRL</kbd> + <kbd>C</kbd> after the message is displayed.

Expected behavior

The entire finally block to complete.

Actual behavior

The finally block is cancelled when <kbd>CTRL</kbd> + <kbd>C</kbd> 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 <kbd>CTRL</kbd> + <kbd>C</kbd> 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
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

6reactions
vexx32commented, Aug 29, 2019

From a user perspective, that might make sense.

From a module author’s perspective, that stance could be really dangerous. Sure, it might be what the user wants, but usually the things you put in a finally block are pretty important. Cancelling a finally block can lead to corrupted data, memory leaks (objects can’t be disposed properly), among a host of other problems.

This should be fixed.

2reactions
vexx32commented, Aug 28, 2019

@SteveL-MSFT @daxian-dbw this is… fairly serious, no? Being able to cancel a finally block seems super not a good thing. 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

If I type Ctrl-C on the command line, will the finally block in ...
I'm running my Java application in cmd.exe in Windows. If I stop the process forcefully by pressing Ctrl-C, and the code at that...
Read more >
try-finally statement (C)
The handler specifies a set of actions that execute when the guarded section is exited. It doesn't matter whether the guarded section is...
Read more >
Try..Finally
Observe that a KeyboardInterrupt exception is thrown and the program exits, but before the program exits, the finally clause is executed and the...
Read more >
Flow control in try catch finally in Java
After executing the catch block, the control will be transferred to finally block(if present) and then the rest program will be executed.
Read more >
try...catch - JavaScript - MDN Web Docs - Mozilla
The finally block contains statements to execute after the try block and catch block(s) execute, but before the statements following the try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found