This is my script in file test.ps1
:
$ErrorActionPreference = "Stop" # make it throw an exception
try
{
Get-Volume -FileSystemLabel "doesnotexist"
}
catch [Microsoft.PowerShell.Cmdletization.Cim.CimJobException]
{
Write-Host "exception thrown"
}
I run it from a PowerShell terminal like this:
./test.ps1
But it does not throw the exception and instead prints out a red error message.
If you're familiar with PowerShell you will understand that it should throw an exception instead.
Why doesn't it throw an exception as expected?