我正在嘗試使用 PowerShell 捕獲特定例外。請看下面的例子:
try {
throw [System.IO.FileNotFoundException]
}
catch [System.IO.FileNotFoundException] {
"File not found"
}
catch {
"Exception type: $($_.Exception.GetType().Name)"
}
此代碼的輸出是:Exception type: RuntimeException
我期待的輸出是:“找不到檔案”
我在這里做錯了什么?
uj5u.com熱心網友回復:
你不能throw <typeName>。您需要拋出例外型別的實體。
throw將陳述句更改為:
throw [System.IO.FileNotFoundException]::new("Failed to find that file you asking for", "<attempted file name/path goes here>")
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/428277.html
標籤:电源外壳
下一篇:嵌套的zip內容串列
