Powershell v2:
try { Remove-Item C:\hiberfil.sys -ErrorAction Stop }
catch [System.IO.IOException]
{ "problem" }
catch [System.Exception]
{ "other" }
Run Code Online (Sandbox Code Playgroud)
当然,我正在使用休眠文件作为示例.实际上还有另一个文件,我希望有时候我可能没有权限删除,我想抓住这种特殊情况.
输出:
output
Run Code Online (Sandbox Code Playgroud)
然而$error[0] | fl * -Force输出System.IO.IOException: Not Enough permission to perform operation.
问题:我不明白为什么我没有用我的第一个catch块捕获此异常,因为这与异常类型匹配.