当远程XML源不可用时处理XmlDataSource [英] Handling XmlDataSource when remote XML source not available

查看:144
本文介绍了当远程XML源不可用时处理XmlDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用XmlDataSource是否有很好的方法来处理在远程XML文件不可用时引起的异常?我对.NET有一些新意,并使用C#。

解决方案

真的由你决定什么适合你的应用程序当这样的异常提出时。你不应该做的唯一的事情是忽略它。



您包含的选项:




  • 自动重试多次,以防连接问题处于暂时状态

  • 向用户返回相应的错误消息,并可能记录或发送电子邮件异常

  • 使用以前缓存的XML文件版本,直到可以获取新的副本

  • 让异常冒泡到调用层,让它处理(可能是记录首先)



您可能还需要做的一件事是清理最后块中的任何资源(例如开放连接) / p>

When using an XmlDataSource is there good way to handle exceptions that are caused when the remote XML file is unavailable? I'm somewhat new to .NET and using C#.

解决方案

It's really up to you to determine what is suitable for your application when an exception like this is raised. The only thing you shouldn't do is ignore it.

Options you have include:

  • Automatically retry a number of times, in case the connection problem is transitory
  • Return an appropriate error message to the user and perhaps log or email the exception
  • Use a previously cached version of the XML file until a fresh copy can be fetched
  • Let the exception bubble up to the calling layer and let it deal with it (perhaps logging it first)

One thing you may also need to do is clean up any resources (e.g. open connections) in a Finally block.

这篇关于当远程XML源不可用时处理XmlDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆