473,383 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Catching HTTP error

Hi,

In my app I've done the following:
.....
wReq=(HttpWebRequest)WebRequest.Create(someURL);
.....
wRes=(HttpWebResponse)(wReq).GetResponse();

On this last line, the GetResponse generates a failure and my app
crashes with an exception error.
The question is: how can I catch this error? I've tried surrounding
the whole stuff with try-catch, but it doesn't enter my catch section!

From IExplorer I can see that they are able to do it: you just get a
blank page with a tiny red cross on it (instead of crashing ....).

Please advise; thank you.

Saya
Nov 19 '05 #1
6 1119
What are you using in your catch block for Exception?

Also, have you tried doing a trap in the Global.Application_Error block?

Clint Hill
H3O Software
http://www.h3osoftware.com
Saya wrote:
Hi,

In my app I've done the following:
....
wReq=(HttpWebRequest)WebRequest.Create(someURL);
....
wRes=(HttpWebResponse)(wReq).GetResponse();

On this last line, the GetResponse generates a failure and my app
crashes with an exception error.
The question is: how can I catch this error? I've tried surrounding
the whole stuff with try-catch, but it doesn't enter my catch section!

From IExplorer I can see that they are able to do it: you just get a
blank page with a tiny red cross on it (instead of crashing ....).

Please advise; thank you.

Saya

Nov 19 '05 #2
It's not possible that it wouldn't go into the catch section if that is set
up to just catch Exception.

You need to show code.

<Saya> wrote in message news:dn********************************@4ax.com...
Hi,

In my app I've done the following:
....
wReq=(HttpWebRequest)WebRequest.Create(someURL);
....
wRes=(HttpWebResponse)(wReq).GetResponse();

On this last line, the GetResponse generates a failure and my app
crashes with an exception error.
The question is: how can I catch this error? I've tried surrounding
the whole stuff with try-catch, but it doesn't enter my catch section!

From IExplorer I can see that they are able to do it: you just get a
blank page with a tiny red cross on it (instead of crashing ....).

Please advise; thank you.

Saya

Nov 19 '05 #3
Hi Marina & Clint,

Here is the (offending ...) code snippet:
-------------------------------------------------
private Image GetImage(string sURL)
{
HttpWebRequest wReq;
HttpWebResponse wRes = null;
Stream str = null;

//Create a web request to the url containing the image
wReq = (HttpWebRequest)WebRequest.Create(sURL);

try
{
//gets the response from the web request
wRes = (HttpWebResponse)(wReq).GetResponse();

//return the image stream from URL specified earlier
str = wRes.GetResponseStream();
}
catch (WebException Ex)
{
MessageBox.Show(Ex.Message);
}

if (str != null)
{
imgImage = new System.Drawing.Bitmap(str);
str.Close();
wRes.Close();
return imgImage;
}
else
return null;
}
------------------------------------------------------------------------------------
Setting a brkpt at the catch line was to no avail ... after executing
the GetResponse line the system pops up an unhandled error and you can
only do a 'Details' or 'Quit' action. Details give just a mere silly
line of 'Main+0xf'.

Appreciate your help!
Saya
================================================== ====
On Tue, 30 Aug 2005 11:08:10 -0400, "Marina" <so*****@nospam.com>
wrote:
It's not possible that it wouldn't go into the catch section if that is set
up to just catch Exception.

You need to show code.

<Saya> wrote in message news:dn********************************@4ax.com...
Hi,

In my app I've done the following:
....
wReq=(HttpWebRequest)WebRequest.Create(someURL);
....
wRes=(HttpWebResponse)(wReq).GetResponse();

On this last line, the GetResponse generates a failure and my app
crashes with an exception error.
The question is: how can I catch this error? I've tried surrounding
the whole stuff with try-catch, but it doesn't enter my catch section!

From IExplorer I can see that they are able to do it: you just get a
blank page with a tiny red cross on it (instead of crashing ....).

Please advise; thank you.

Saya


Nov 19 '05 #4
Ok, that's in the debugger. It's trying to tell you as soon as there is a
problem.

If you just run the executable, it should work as expected.

If what you have is running in ASP.NET, then you won't see the message box
of course, since that would appear on the server, not in the client browser.

"victor" <vi************@hotmail.com> wrote in message
news:9l********************************@4ax.com...
Hi Marina & Clint,

Here is the (offending ...) code snippet:
-------------------------------------------------
private Image GetImage(string sURL)
{
HttpWebRequest wReq;
HttpWebResponse wRes = null;
Stream str = null;

//Create a web request to the url containing the image
wReq = (HttpWebRequest)WebRequest.Create(sURL);

try
{
//gets the response from the web request
wRes = (HttpWebResponse)(wReq).GetResponse();

//return the image stream from URL specified earlier
str = wRes.GetResponseStream();
}
catch (WebException Ex)
{
MessageBox.Show(Ex.Message);
}

if (str != null)
{
imgImage = new System.Drawing.Bitmap(str);
str.Close();
wRes.Close();
return imgImage;
}
else
return null;
}
------------------------------------------------------------------------------------
Setting a brkpt at the catch line was to no avail ... after executing
the GetResponse line the system pops up an unhandled error and you can
only do a 'Details' or 'Quit' action. Details give just a mere silly
line of 'Main+0xf'.

Appreciate your help!
Saya
================================================== ====
On Tue, 30 Aug 2005 11:08:10 -0400, "Marina" <so*****@nospam.com>
wrote:
It's not possible that it wouldn't go into the catch section if that is
set
up to just catch Exception.

You need to show code.

<Saya> wrote in message news:dn********************************@4ax.com...
Hi,

In my app I've done the following:
....
wReq=(HttpWebRequest)WebRequest.Create(someURL);
....
wRes=(HttpWebResponse)(wReq).GetResponse();

On this last line, the GetResponse generates a failure and my app
crashes with an exception error.
The question is: how can I catch this error? I've tried surrounding
the whole stuff with try-catch, but it doesn't enter my catch section!

From IExplorer I can see that they are able to do it: you just get a
blank page with a tiny red cross on it (instead of crashing ....).

Please advise; thank you.

Saya

Nov 19 '05 #5
OK, thanks. I'll look into it again tomorrow - it's quite late at my
place rigth now.
greetz
------------------------------------------------------------------------------------------
On Tue, 30 Aug 2005 13:43:48 -0400, "Marina" <so*****@nospam.com>
wrote:
Ok, that's in the debugger. It's trying to tell you as soon as there is a
problem.

If you just run the executable, it should work as expected.

If what you have is running in ASP.NET, then you won't see the message box
of course, since that would appear on the server, not in the client browser.

"victor" <vi************@hotmail.com> wrote in message
news:9l********************************@4ax.com.. .
Hi Marina & Clint,

Here is the (offending ...) code snippet:
-------------------------------------------------
private Image GetImage(string sURL)
{
HttpWebRequest wReq;
HttpWebResponse wRes = null;
Stream str = null;

//Create a web request to the url containing the image
wReq = (HttpWebRequest)WebRequest.Create(sURL);

try
{
//gets the response from the web request
wRes = (HttpWebResponse)(wReq).GetResponse();

//return the image stream from URL specified earlier
str = wRes.GetResponseStream();
}
catch (WebException Ex)
{
MessageBox.Show(Ex.Message);
}

if (str != null)
{
imgImage = new System.Drawing.Bitmap(str);
str.Close();
wRes.Close();
return imgImage;
}
else
return null;
}
------------------------------------------------------------------------------------
Setting a brkpt at the catch line was to no avail ... after executing
the GetResponse line the system pops up an unhandled error and you can
only do a 'Details' or 'Quit' action. Details give just a mere silly
line of 'Main+0xf'.

Appreciate your help!
Saya


Nov 19 '05 #6
Found it .... at last!
For what it's worth, the solution to my situation is: *not* using
'WebException' in the catch block, but use the plain 'Exception'!

Bit weird, but it works that way, it now enters my catch block when an
error turned up. Don't ask me why/how, I'm quite new to all these
stuff. Forgot to mention that it concerns a SmartDevice target running
under WinCE / CompactFramework.

victor
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Keith Bolton | last post by:
I am handling exceptions currently using try, except. Generally I don't handle specific exceptions and am catching all. Then if an exception occurs, I would like to capture that error string....
8
by: Adam H. Peterson | last post by:
Hello, I sometimes find myself writing code something like this: try { Derived &d=dynamic_cast<Derived&>(b); d.do_something_complicated(); // etc.... } catch (std::bad_cast) { throw...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
2
by: Geoff O | last post by:
I have a try catch block in a web service that executes ADO.NET code that interfaces with an Oracle database. In addition, I have a try catch block in the client around the call to the web...
3
by: Peter A. Schott | last post by:
I know there's got to be an easy way to do this - I want a way to catch the error text that would normally be shown in an interactive session and put that value into a string I can use later. I've...
7
by: Derek Schuff | last post by:
I'm sorry if this is a FAQ or on an easily-accesible "RTFM" style page, but i couldnt find it. I have some code like this: for line in f: toks = line.split() try: if int(toks,16) ==...
2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
2
by: fischermx | last post by:
Exception Catching difference between VC++ and C# In C# I have this: try { int x, y, z; x = 20; y = 0;
12
by: Karlo Lozovina | last post by:
I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.