Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Try not catching Drive_not_found

$
0
0

I was surprised that the below checking of a non-existing drive does not transfer control to the Catch area. Why is that?

$DebugPreference = "Continue"                         

try {
    Write-Debug "Before Error"
    Get-ChildItem -Path "Q:\"    # Q is a non-existing drive.
    Write-Debug "After Error"
    Write-Debug ("Error in Try block: " + $Error[0])
}
catch {
    Write-Debug "Catch"
    Write-Debug ("Error in Catch block: " + $_.Exception.Message)
}


-Tom. Microsoft Access MVP


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>