当我运行我的程序时,代码正确捕获了超时异常,但随后我收到一条弹出消息:
Microsoft.VisualBasic.dll 中出现了“System.NullReferenceException”类型的第一次机会异常
还这样说:
未设置对象变量或 With 块变量。
这是我的代码:
Dim rt As String = ""
Dim out As String
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
Dim time As Date
time = Now()
Try
wRequest = WebRequest.Create(Address)
wRequest.Timeout = 10000
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Catch wex As System.Net.WebException
If wex.Status = WebExceptionStatus.Timeout Then
MessageBox.Show("Could not establish a connection to the selected exchange server.", "Connection Timed Out", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Try