2011-06-26 77 views
0

我想抛出,如果在我的方法调用失败的异常,我的代码是迄今为止如下:C# - 抛出一个异常,如果无法连接到删除服务器

if (sourceFile.Exists) 
      // Would be nice to add ticker/spinner, while the file header on the remote server is being read!! 
      { 
       var request = (HttpWebRequest)WebRequest.Create(@"http://google.com/test.zip"); 
       request.Method = "HEAD"; 
       var response = (HttpWebResponse)request.GetResponse(); 

       if (response.LastModified > sourceFile.LastWriteTime) 
       { 

        Download_Click(sender, e); 

        // use response.GetStream() to download the file. 
       } 
+4

你有什么问题吗? –

+0

@ba__friend如果没有网络连接可用,我如何捕获异常 –

+0

不要帮助,它已经发生。 –

回答

2

按照HttpWebRequest文档,一个WebExceptionGetResponse如果在处理它发生请求超时或另一错误抛出。

你应该能够在你的代码中捕捉到它。

相关问题