Powershell v2:
try { Remove-Item C:\hiberfil.sys -ErrorAction Stop }
catch [System.IO.IOException]
{ "problem" }
catch [System.Exception]
{ "other" }
I'm using the hibernation file as an example, of course. There's actually another file that I expect I may not have permission to delete sometimes, and I want to catch this exceptional situation.
Output:
output
and yet $error[0] | fl * -Force outputs System.IO.IOException: Not Enough permission to perform operation.
Problem: I don't see why I'm not catching this exception with my first catch block, since this matches the exception type.