Why do i get a warning with my http? Trying to come to terms with try catch finally end try
the code in the finally block to close the stream that may or may not have produced an error gives me a warning that the code may produce a null value, even with both an exception handler and with a null value handler.Code:Dim myhttp As HttpWebRequest Dim html As String = "" Dim responseStream As Stream Dim WebResponse As HttpWebResponse Try myhttp = CType(WebRequest.Create(url), HttpWebRequest) WebResponse = CType(myhttp.GetResponse(), HttpWebResponse) responseStream = WebResponse.GetResponseStream() Dim reader As StreamReader = New StreamReader(responseStream, Encoding.Default) html = reader.ReadToEnd() Catch ex As HttpException MsgBox("Validation HTTP error" & vbCrLf & ex.Message) Catch ex As NullReferenceException MsgBox("Null value returned error") Catch ex As Exception MsgBox("Validation Other Exception error" & vbCrLf & ex.Message) Finally responseStream.Close() End Try
I read about using nested try catch end try and wonder if i should try again if i get an error. Is it possible to say do the block if it errors give the user the option to try again or abort the app?
(afterthought this is sending an encrypted string to a server to validate before the app gives full access)




Reply With Quote