You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should run the catch [System.Management.Automation.ItemNotFoundException] statement and output "ItemNotFoundException caught: ...".
Actual behavior
It runs the more general catch statement and outputs:
DOH! Exception caught: System.Management.Automation.ItemNotFoundException - Cannot find path 'C:\xyzzy' because it does not exist.
Even though the exception type is System.Management.Automation.ItemNotFoundException.
If you remove [System.Exception] from the last catch statement, this script works as expected and the specific catch statement executes. OR, if you change the $worksAsExpected to $true this will directly throw that exception in which case the more specific catch executes even with [System.Exception] on the last catch.
Steps to reproduce
Execute this code:
Expected behavior
This should run the
catch [System.Management.Automation.ItemNotFoundException]statement and output "ItemNotFoundException caught: ...".Actual behavior
It runs the more general catch statement and outputs:
Even though the exception type is
System.Management.Automation.ItemNotFoundException.If you remove
[System.Exception]from the last catch statement, this script works as expected and the specific catch statement executes. OR, if you change the$worksAsExpectedto$truethis will directly throw that exception in which case the more specific catch executes even with[System.Exception]on the last catch.Environment data
Windows 10 1607 - Build14393.187