Finally clause can be canceled with CTRL + C
See original GitHub issueSteps 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:
- Created 4 years ago
- Reactions:2
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 afinally
block can lead to corrupted data, memory leaks (objects can’t be disposed properly), among a host of other problems.This should be fixed.
@SteveL-MSFT @daxian-dbw this is… fairly serious, no? Being able to cancel a
finally
block seems super not a good thing. 😦