您现在的位置是:网站首页> 编程资料编程资料
PowerShell中捕获异常时的行号和列号的方法_PowerShell_
2023-05-26
403人已围观
简介 PowerShell中捕获异常时的行号和列号的方法_PowerShell_
如果自己写函数动态地去执行一些脚本块或者脚本文件,那么捕获到异常时行号和列号信息非常有用。例如脚本文件:
复制代码 代码如下:
trap{
$info=$_.InvocationInfo
"在第{0}行,第{1}列捕获到异常:{2}" -f $info.ScriptLineNumber,$info.OffsetInLine ,$_.Exception.Message
continue
}
get-date
1gb/2kb
Get-Service | foreach {1/0}
执行结果为:
复制代码 代码如下:
Thursday, June 26, 2014 4:41:41 PM
524288
在第9行,第15列捕获到异常:Attempted to divide by zero.
您可能感兴趣的文章:
相关内容
- Powershell获取环境变量的方法_PowerShell_
- Powershell的break、continue和return简单总结_PowerShell_
- 了解Powershell中的Exit函数_PowerShell_
- Powershell获取图片名字、文件夹及拍摄时间的例子_PowerShell_
- PowerShell默认参数$PSDefaultParameterValues结合Out-File输出到日志文件_PowerShell_
- Powershell批量给文件增加前辍实例_PowerShell_
- PowerShell把文件删除到回收站的方法_PowerShell_
- PowerShell脚本性能优化技巧总结_PowerShell_
- powershell操作word详解_PowerShell_
- PowerShell中运行CMD命令的技巧总结(解决名称冲突和特殊字符等问题)_PowerShell_
