1、服务器端错误处理:

[EnableClientAccess()]
public class DomainService1 : DomainService
{    
  public IEnumerable<Customer> GetCustomers()    
  {        
    throw new ApplicationException("My exception");    
  }    
  protected override void OnError(DomainServiceErrorInfo errorInfo)    
  {         
    //记录错误
  } }

可以在web.config中设置出现错误时导航到错误页:

<customErrors mode="On" defaultRedirect="GenericErrorPage.htm"/>

2、客户端错误处理:

当SL执行load操作时,会抛出异常,如果没有处理会调用Application_UnhandledException,引起白屏。可以这样处理:

customerDomainContext.Load<Customer>(ds.GetCustomersQuery(),  
loadOperation =>
{
if (loadOperation.HasError)
  {
    MessageBox.Show(loadOperation.Error.Message);
    loadOperation.MarkErrorAsHandled();
  }
}
,null);

 

相关文章:

  • 2021-06-30
  • 2022-03-05
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-07-07
  • 2021-06-11
  • 2022-12-23
  • 2021-08-27
  • 2021-12-01
相关资源
相似解决方案