首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何防止webexception消息?

如何防止webexception消息?
EN

Stack Overflow用户
提问于 2016-07-20 19:28:45
回答 1查看 42关注 0票数 0

我的C# windows窗体应用程序从url下载一个简短的字符串。它解析字符串并显示信息。它完全是用来做这个的。一种弹出式程序。我使用的是:

代码语言:javascript
复制
using (WebClient wc = new WebClient())
{
string json = wc.DownloadString(url);
//parse the string
//show windows form with the gathered data 
this.Show()
}

我的问题是,当没有互联网连接时,会弹出未处理的异常错误。我认为我需要防止这个错误消息,只需要保持程序运行,直到连接恢复。如何防止消息并保持其运行?

EN

回答 1

Stack Overflow用户

发布于 2016-07-20 19:30:16

使用try .. catch块结构,如

代码语言:javascript
复制
using (WebClient wc = new WebClient())
{
try {
string json = wc.DownloadString(url);
//parse the string
//show windows form with the gathered data 
this.Show()
}
catch(exception ex) { //Log the exception with datetime }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38480047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档