【发布时间】:2017-03-01 10:07:43
【问题描述】:
如何在 PowerShell 中使用“抛出”方向来抛出自定义数据对象的异常? 说吧,能做到吗?:
throw 'foo', $myData
那么数据可以用在'catch'逻辑中:
catch {
if ($_.exception.some_property -eq 'foo') {
$data = $_.exception.some_field_to_get_data
# dealing with data
}
}
编辑:
我的目的是知道是否有一个简短而酷的语法来抛出一个异常(无需显式创建我自己的类型),我可以通过它的名称来决定它的名称并在“catch”块中处理它的数据。
【问题讨论】:
标签: powershell exception throw