![](/img/trans.png)
[英]Powershell: Throwing Exception in Catch block terminates but does not output Exception to console
[英]PowerShell catch exception in Param() block
Param(
[ValidateRange(21,90)]
[int[]]$Age
)
$age
超出范围时如何捕获异常?
正如评论中所指出的,需要在调用上下文中捕获验证错误
try{
.\Set-Age.ps1
}
catch [System.Management.Automation.ParameterBindingException] {
Write-Host "Error thrown while attempting to bind an argument to parameter $($_.Exception.ParameterName), with message: $($_.Exeption.Message)"
}
catch {
# something other than the parameter binder threw an exception
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.