【发布时间】:2011-03-25 21:04:44
【问题描述】:
我有一个 aspx 页面,单击按钮会创建一个 serviceRefernece 对象的实例。在我的页面后面的代码中,我将调用包装在 try/catch 中。
try
{
var client = GetClient();
var request = new ActiveVerificationRequestDC();
var response = client.GetActiveVerification(request);
DoSomethingWithTheResponse(response);
}
catch (FaultException ex)
{
LogError(ex, MethodBase.GetCurrentMethod().Name);
throw;
}
catch (Exception ex)
{
var args = new[] { MethodBase.GetCurrentMethod().Name, ex.Message };
DisplayError(args);
}
引用的 svc 文件使用几乎相同的模式。它通过 net.tcp 调用内部客户端。调用包含在 try/catch 中
try
{
var client = new InternalServiceClient();
var response = client.GetActiveVerification(request);
client.Close();
return response;
}
catch (FaultException fe)
{
LogError(MethodBase.GetCurrentMethod().Name, fe);
throw;
}
这是我的问题,如何让错误出现在我的 UI catch 语句中?当我这样离开时,我从 Visual Studio 收到一个未处理的异常错误。我尝试删除throw,这让我指定了一个返回值,然后我返回null。这会使 UI 无法正常工作。我已经尝试过throw new Exception(fe.message),但未处理的异常也遇到了同样的问题。基本上我的问题是我怎样才能完成我所需要的?我错过了什么?
【问题讨论】:
-
未处理的异常听起来像是发生在服务边界上,因此 Visual Studio 会捕获它。 Visual Studio 不会让你继续执行吗?我想你的页面
catch (Exception ex)或catch (FaultException ex)捕获处理程序永远不会执行?
标签: c# asp.net exception exception-handling try-catch