【发布时间】:2014-07-24 11:26:19
【问题描述】:
我需要找到最好的方法来做到这一点,
try
{
// Service call.
}
catch (FaultException exception)
{
service.Abort();
throw new FaultException(Resources.UnexpectedErrorOccurredAtServer, exception);
}
或者
catch (FaultException exception)
{
service.Abort();
throw new Exception(Resources.UnexpectedErrorOccurredAtServer, exception);
}
// 调用者。
Main()
{
try
{
serviceCaller()
}
catch(FaultException ex)
{
// Should we have this catch???
}
catch( Exception ex)
{
// Handle unexpected errors.
}
向调用者抛出预期异常的最佳方法是什么。 如果我们抛出 FaultException,调用者的 main 方法应该显式处理它,否则一般的异常都会起作用。
【问题讨论】:
标签: c# wcf exception-handling