本帖最后由 flashercs 于 2022-7-10 18:04 编辑
- $ErrorActionPreference = 'Stop'
- try{
- # comment
- copy 'abc' 'efdf'
-
- }catch{
- 'At line:{0} char:{1}' -f $_.InvocationInfo.ScriptLineNumber,$_.InvocationInfo.OffsetInLine
- }
复制代码 powershell的exception分为两类:termination error, non termination error.只有致命错误才能被catch 捕获. |