【发布时间】:2013-09-06 19:15:20
【问题描述】:
我在从 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 字符:18 + $myService = New-WebServiceProxy -Uri
"http://localhost/someservice.svc"+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (http://localhost/someservice.svc:Uri) [New-WebServiceProxy], WebExc 选项 + FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
有人可能会问我为什么 try catch 不捕获这个异常?感谢您的任何回答
【问题讨论】:
标签: web-services exception powershell exception-handling new-webserviceproxy