我在从 NewWebServiceProxy cmdlet 捕获异常时遇到问题
try {
$myService = New-WebServiceProxy -Uri "http://localhost/someservice.svc"
}
catch {
Write-Log ([string]::Format("Error : {0}", $_.Exception.Message))
}
当我运行它时,我得到了这个未处理的异常:New-WebServiceProxy:
请求失败,HTTP 状态为 404:未找到。在 C:\Users\SomeUser\AppData\Local\Temp\d052b604-38ad-4827-b952-4ebc66e79c69.ps1:2 char:18 + $myService = New-WebServiceProxy -Uri
"http://localhost/someservice.svc"
+ ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CategoryInfo : ObjectNotFound: (http://localhost/someservice.svc:Uri
) [New-WebServiceProxy], WebExc eption + FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
有人可能会问我为什么 try catch 不捕获这个异常?感谢您的回答