testing for exceptions

C

Cerebrus99

Hi,

Why not try the generic Exception class.
Use it's properties to give you more information about the error. As in:

Try
' your code here
Catch ex as Exception
Msgbox(ex.Message)
Finally
MyRequest.Close()
End Try

Hope this helps,

Regards,
Cerebrus.
 
T

TerryFei

Hi Cj,
Welcome to MSDN Newsgroup!
I agree with Cerebrus's point. We can use try/catch statement to catch
exception and get more information why it failed.
Have a nice day!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security


--------------------
 
J

Jay B. Harlow [MVP - Outlook]

cj,
In addition to the other comments, I normally use something like:

Dim uri As New Uri("http://www.tsbradley.net")
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(uri),
HttpWebRequest)
Dim response As HttpWebResponse
Try
response = DirectCast(request.GetResponse(), HttpWebResponse)
Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse
response = DirectCast(ex.Response, HttpWebResponse)
End Try

Then I am able to use response.StatusCode to see what the HTTP status
returned was:

Debug.WriteLine(response.StatusCode, "statusCode")

The:

Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse

Will only catch WebExceptions where the WebException.Response is of type
HttpWebResponse, other exceptions will continue up to a higher exception
handler...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| HttpWebRequest.Create(String) doesn't return any error codes but it does
| show exceptions
|
http://msdn.microsoft.com/library/d...frlrfsystemnetwebrequestclasscreatetopic1.asp
| When I run
| REQUEST = Net.HttpWebRequest.Create(URI)
| How do I test to see if it has worked? And if it didn't which of these
| exceptions occured. I'd hope I don't have to do and if for each one
| just in case.
|
| Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top