-
Jul 7th, 2012, 12:53 PM
#1
Thread Starter
Lively Member
[RESOLVED] Try Catch not Working?
I have this code
Code:
Try
Dim myWebRequest As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
myWebRequest.Method = "GET"
myWebRequest.Timeout = (My.Settings.timeout) * 1000
Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)
Dim myWebSource As New StreamReader(myWebResponse.GetResponseStream())
myPageSource = myWebSource.ReadToEnd()
myWebResponse.Close()
myWebSource.Close()
myWebRequest.Abort()
Return myPageSource
Catch ex As Exception
Return ""
End Try
If there is an error i would expect it to not throw an error but just return a ""
But when in debug sometimes I get an error thrown at this line:
Code:
Dim myWebResponse As HttpWebResponse = DirectCast(myWebRequest.GetResponse(), HttpWebResponse)
And it shows the dialog box. Is this because its in debug mode. Im quite sure this is not true. So why is it showing the error even the whole code is in a Try Catch loop
-
Jul 7th, 2012, 01:05 PM
#2
Re: Try Catch not Working?
It does not matter if you step thu the code via a break point, when the exception is raised the catch part of the try kicks in so this seems wrong that an exception is propagated to the UI instead of the catch.
-
Jul 7th, 2012, 01:09 PM
#3
Thread Starter
Lively Member
Re: Try Catch not Working?
is it to do with the "directcast" bit?
-
Jul 7th, 2012, 01:10 PM
#4
Re: Try Catch not Working?
What's the error? And, dialog box?
-
Jul 7th, 2012, 01:45 PM
#5
Thread Starter
Lively Member
Re: Try Catch not Working?
Originally Posted by dunfiddlin
What's the error? And, dialog box?
its ok i sorted it.
debug menu>exceptions>...
I had set all system errors to "THROWN"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|