473,666 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

testing for exceptions

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.HttpWebRequ est.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
4 950
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.Messa ge)
Finally
MyRequest.Close ()
End Try

Hope this helps,

Regards,
Cerebrus.

"cj" <cj@nospam.nosp am> wrote in message
news:OF******** ******@TK2MSFTN GP12.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/
frlrfsystemnetw ebrequestclassc reatetopic1.asp When I run
REQUEST = Net.HttpWebRequ est.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
Hi,

If request is nothing then it failed.

Ken
--------------
"cj" <cj@nospam.nosp am> wrote in message
news:OF******** ******@TK2MSFTN GP12.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.HttpWebRequ est.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
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.nosp am>
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.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 208.254.170.98
Lines: 1
Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
Xref: TK2MSFTNGXA01.p hx.gbl microsoft.publi c.dotnet.langua ges.vb:317700
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

HttpWebRequest .Create(String) doesn't return any error codes but it does
show exceptions
http://msdn.microsoft.com/library/de...-us/cpref/html /frlrfsystemnetw ebrequestclassc reatetopic1.aspWhen I run
REQUEST = Net.HttpWebRequ est.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
cj,
In addition to the other comments, I normally use something like:

Dim uri As New Uri("http://www.tsbradley.n et")
Dim request As HttpWebRequest = DirectCast(WebR equest.Create(u ri),
HttpWebRequest)
Dim response As HttpWebResponse
Try
response = DirectCast(requ est.GetResponse (), HttpWebResponse )
Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse
response = DirectCast(ex.R esponse, HttpWebResponse )
End Try

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

Debug.WriteLine (response.Statu sCode, "statusCode ")

The:

Catch ex As WebException When TypeOf ex.Response Is HttpWebResponse

Will only catch WebExceptions where the WebException.Re sponse 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.nosp am> wrote in message
news:OF******** ******@TK2MSFTN GP12.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.HttpWebRequ est.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
5804
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is held in memory and therefore fast, without risk of damaging real files, and with none of the messiness of leftover files after testing. Googling the archives and the web suggests that only I and Remy Blank have done much along these lines. I...
16
2667
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an option. Let's call the id of a class "cid" (for "class id"). The function signature should look like this: ******************************************
6
1624
by: Vikram Paranjape | last post by:
Hi, I wrote a small test script to utilize the ScopeGuard class from the Dec 2000 CUJ article. I noted that my cleanup function was being called on normal block exit, but not on calling a function I wrote to throw an exception. #include <iostream> #include <exception>
5
2862
by: Pete | last post by:
Hi folks, I've been looking at unit testing frameworks (csUnit, NUnit, etc) and have gathered some info on them (see the older thread on c# 2004). My question is this: how do they work with windows forms? All the samples I've seen are for trivial testing, such as making sure a property sets it's value correctly. How would I go about testing, for example, a custom control? All my testing seems to be visual (i.e. compile, run, see if it...
3
3209
by: Ole Hanson | last post by:
Hi I am trying to engineer a way of testing that my logging framework is capable of writing to my eventlog. I want to include this test in my already existing NUnit tests - but I'm a little low on ideas as how to assert that I actually did write to the eventlog successfully. Naturally I want this assertion without having to open my eventlog and visually verify the writing.
0
1492
by: Brian Russell | last post by:
We have three servers (beyond my development box) in our organization. The first is a testing server that has IIS and SQL Server on it. The second is another testing server that also has IIS and SQL Server. The final is the production box that only has IIS. I develop on my own machine, copy to the first testing server, the code is tested, copy the code from testing 1 to testing 2, the code is tested again, and then copy testing 2 code...
6
1588
by: Dick | last post by:
I’d appreciate some advice regarding unit tests. My questions are general in nature but (as usual) best conveyed via a (simplified) example: I have a table that contains two columns – the name of a PC and the date/time that an event took place. I have a stored procedure that accepts two date arguments – a start date/time and an end date/time. It returns a list of PC’s and the number of times the event took place within the...
10
3911
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about py.test and nose. Are there other options? Is there any kind of concensus about the best, or at least how they stack up to each other? Brendan
3
2486
by: IanWright | last post by:
I'm currently in the process of writing a class library, and I'm attempting to write as many unit tests as possible to ensure that I can weed out all the mistakes early on. Part of this involves testing that various properties catch Exceptions if set to null, so I don't need to extensively check this later on in the program and slow down my heuristics. What I'm interested in, is if anyone knows of an easy way of testing for Exceptions...
0
8449
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8360
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8876
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8556
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8642
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.