By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

testing for exceptions

P: n/a
cj
HttpWebRequest.Create(String) doesn't return any error codes but it does
show exceptions
http://msdn.microsoft.com/library/de...eatetopic1.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
Feb 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

"cj" <cj@nospam.nospam> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
HttpWebRequest.Create(String) doesn't return any error codes but it does
show exceptions
http://msdn.microsoft.com/library/de...us/cpref/html/
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

Feb 14 '06 #2

P: n/a
Hi,

If request is nothing then it failed.

Ken
--------------
"cj" <cj@nospam.nospam> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
HttpWebRequest.Create(String) doesn't return any error codes but it does
show exceptions
http://msdn.microsoft.com/library/de...eatetopic1.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

Feb 15 '06 #3

P: n/a
Hi Cj,
Welcome to MSDN Newsgroup!
How do I test to see if it has worked?
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
--------------------Date: Tue, 14 Feb 2006 14:24:17 -0500
From: cj <cj@nospam.nospam>
User-Agent: Thunderbird 1.5 (Windows/20051201)
MIME-Version: 1.0
Subject: testing for exceptions
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <OF**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 208.254.170.98
Lines: 1
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.dotnet.languages.vb:317700
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

HttpWebRequest.Create(String) doesn't return any error codes but it does
show exceptions
http://msdn.microsoft.com/library/de...-us/cpref/html /frlrfsystemnetwebrequestclasscreatetopic1.aspWhen 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


Feb 15 '06 #4

P: n/a
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
"cj" <cj@nospam.nospam> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
| HttpWebRequest.Create(String) doesn't return any error codes but it does
| show exceptions
|
http://msdn.microsoft.com/library/de...eatetopic1.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
Feb 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.