473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page_Error, Application_Error and HttpUnhandledException

I've been reading the O'Reilly "ASP.NET Cookbook" 1st edition (Kittel and
LeBlond), and it makes a recommendation about exception handling that seems
a bit strange. They say that, if you want to let some exceptions propagate
up to Application_Error, you should include the following Page_Error on
every page:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Throw Server.GetLastError()
End Sub

Their reasoning is that this prevents ASP.NET from wrapping your exception
in an HttpUnhandledException. They say that this wrapping is not 100%
consistent, so you need the Page_Error handler to make it easy for your
Application_Error handler to find the "real" exception.

I tried this out (actually I added the Page_Error handler to a class derived
from System.Web.UI.Page so I don't have to add it to every page) and, sure
enough, it prevents the HttpUnhandledException. But I seem to pay a high
price for it. When, after Application_Error is done, I get the ASP yellow
error screen on my workstation, it no longer pinpoints the line and stack
that caused the exception. Instead, it always shows the "Throw
Server.GetLastError()" line and the stack for the call to Page_Error! Not
very helpful. Sure, I could write the real error to the event log and read
it there - but what a drag.

Has anyone else thought about using/not using this technique?

Thanks in advance,
Carl Johansen
www.carljohansen.co.uk


Nov 19 '05 #1
2 2104
I'm not 100% sure but I use Server.GetLastError().GetBaseException() and I
think that gets by and HttpUnhandledException issues. I'm not sure exactly
what the real probleem is anyway but I've not had any issues using the above
(in teh Application_Error procedure) to get what I need.

--Buddy
"Carl Johansen" <carl@_NOSPAM_carljohansen.co.uk> wrote in message
news:Op**************@TK2MSFTNGP14.phx.gbl...
I've been reading the O'Reilly "ASP.NET Cookbook" 1st edition (Kittel and
LeBlond), and it makes a recommendation about exception handling that seems a bit strange. They say that, if you want to let some exceptions propagate up to Application_Error, you should include the following Page_Error on
every page:

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
Throw Server.GetLastError()
End Sub

Their reasoning is that this prevents ASP.NET from wrapping your exception
in an HttpUnhandledException. They say that this wrapping is not 100%
consistent, so you need the Page_Error handler to make it easy for your
Application_Error handler to find the "real" exception.

I tried this out (actually I added the Page_Error handler to a class derived from System.Web.UI.Page so I don't have to add it to every page) and, sure
enough, it prevents the HttpUnhandledException. But I seem to pay a high
price for it. When, after Application_Error is done, I get the ASP yellow
error screen on my workstation, it no longer pinpoints the line and stack
that caused the exception. Instead, it always shows the "Throw
Server.GetLastError()" line and the stack for the call to Page_Error! Not
very helpful. Sure, I could write the real error to the event log and read it there - but what a drag.

Has anyone else thought about using/not using this technique?

Thanks in advance,
Carl Johansen
www.carljohansen.co.uk

Nov 19 '05 #2
The point of HttpUnhandledException is to let you know if the error was during
processing of your pages or if the error was from something else, such as
a configuration error, a page compiler error, or a 404 error. Many times
in Application_Error you check:

void Application_Error(...)
{
if (Context.Error is HttpUnhandledException)
{
// ok, this is a runtime code problem
}
else
{
// ok, this is something else
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
I've been reading the O'Reilly "ASP.NET Cookbook" 1st edition (Kittel
and LeBlond), and it makes a recommendation about exception handling
that seems a bit strange. They say that, if you want to let some
exceptions propagate up to Application_Error, you should include the
following Page_Error on every page:

Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles MyBase.Error
Throw Server.GetLastError()
End Sub
Their reasoning is that this prevents ASP.NET from wrapping your
exception in an HttpUnhandledException. They say that this wrapping
is not 100% consistent, so you need the Page_Error handler to make it
easy for your Application_Error handler to find the "real" exception.

I tried this out (actually I added the Page_Error handler to a class
derived from System.Web.UI.Page so I don't have to add it to every
page) and, sure enough, it prevents the HttpUnhandledException. But I
seem to pay a high price for it. When, after Application_Error is
done, I get the ASP yellow error screen on my workstation, it no
longer pinpoints the line and stack that caused the exception.
Instead, it always shows the "Throw Server.GetLastError()" line and
the stack for the call to Page_Error! Not very helpful. Sure, I
could write the real error to the event log and read it there - but
what a drag.

Has anyone else thought about using/not using this technique?

Thanks in advance,
Carl Johansen
www.carljohansen.co.uk


Nov 19 '05 #3

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

Similar topics

2
2794
by: fump75 | last post by:
Hello, I would like to show an error message in a user control when an exception is thrown. This message should be built in Page_error or Application_error event and i don't manage to reach a...
4
6203
by: Alex Nitulescu | last post by:
Hi. I read about Page_Error and Application_Error. However, I provoke an error in a page but still Page_Error won't run. This is all the code I have left in my page: ...
4
1453
by: Michael | last post by:
Using some example code I've found, I'm trying to do the custom error page thing. I have the following in global.asax.. Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim...
1
3698
by: Buddy Ackerman | last post by:
I have a page where users upload files. I have the maxRequestLength set and have created a Page_Error procedure to trap the error when someone load a file that is larger than the maxRequestLength....
6
4544
by: Matt | last post by:
Can anyone give me a good reason to use BOTH application scope Page_Error and the page scope Page_Error when trapping errors in a web application? Is there any real benefit to using the Page_Error...
2
2115
by: Matt | last post by:
As the subject says... are Application_Error and Page_Error triggered by the same event? In other words, is there any error that could slip by Application_Error but be caught by Page_Error, or...
3
1255
by: Carlo Razzeto | last post by:
Is there anyway to inline Page_Error type global error handling in an ASP.Net webpage? Currently I work on a very large web system where the entier web front end is contained in a single project...
2
4704
by: Cramer | last post by:
I'm developing a new ASP.NET 3.5 app and I have an http module hooked up to Application_Error that logs detailed exception data. When it parses and evaluates unhandled exceptions, it "sees" all...
2
1436
by: Erik Lautier | last post by:
I've got Page_Error emailing me the message and stack trace when a server error is generated, but it doesn't always work. My Page_Error code: Sub Page_Error(ByVal src As Object, ByVal args As...
0
7105
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...
0
7308
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,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
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...
0
5617
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,...
1
5037
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...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.