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

Error Handleing at the Application Level Server Error

P: n/a
Howdy,

I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel
and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
application level error handling. Most of my functions have try..catch to
email me about an error, then I want the application level to fire off to
send the user to a custom page AND log it in the app log. When an error
occurs on my page, i get a server error

Server Error in '/newcart' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code. Exception Details:
System.NullReferenceException: Object reference not set to an instance of an
object.Source Error: Line 4:
Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Line 6: Throw Server.GetLastError()
Line 7: End Sub
Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb Line:
6 Any ideas?Also, I'm under the impression that if an actual error occurs,
it will not send me to the error page as specified b/c I'm on my development
machine. is that correct?Thanks!!-- David
Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com

Jul 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
David,
You shouldn't have to rethrow the sever last error in your page_error
event. As long as you don't call Server.ClearError() the Application_Error
event should still fire and redirection to the error page should occur as
defined in your web.config.

Incidentally, I normally use the Page_Error event to perform page state
clean up and the Application_Error event in the global.asax for custom error
handling (such as calling an EntLib exception policy - which could you caould
configure to do your emailing and logging functions).

Depending on the deployment I sometimes use a custom HTTPModule for hooking
in to application events. If I want to change how I'm handling an
application error then I cna change and redeploy th HTTPModule dll rather
than playing with the global.asax.

Hope this helps,
Garth

"David Lozzi" wrote:
Howdy,

I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel
and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
application level error handling. Most of my functions have try..catch to
email me about an error, then I want the application level to fire off to
send the user to a custom page AND log it in the app log. When an error
occurs on my page, i get a server error

Server Error in '/newcart' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code. Exception Details:
System.NullReferenceException: Object reference not set to an instance of an
object.Source Error: Line 4:
Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Line 6: Throw Server.GetLastError()
Line 7: End Sub
Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb Line:
6 Any ideas?Also, I'm under the impression that if an actual error occurs,
it will not send me to the error page as specified b/c I'm on my development
machine. is that correct?Thanks!!-- David
Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com

Jul 20 '06 #2

P: n/a
The book states to "rethrow the last exception that occured...we do this
step to avoid having the exception information wrapped with an
HttpUnhandledException exception. ASP.NET automatically creates a new
HttpUnhandledException at the page level unless you rethrow the last
exception." sooo.....

--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com
"GarthS" <Ga****@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
David,
You shouldn't have to rethrow the sever last error in your page_error
event. As long as you don't call Server.ClearError() the
Application_Error
event should still fire and redirection to the error page should occur as
defined in your web.config.

Incidentally, I normally use the Page_Error event to perform page state
clean up and the Application_Error event in the global.asax for custom
error
handling (such as calling an EntLib exception policy - which could you
caould
configure to do your emailing and logging functions).

Depending on the deployment I sometimes use a custom HTTPModule for
hooking
in to application events. If I want to change how I'm handling an
application error then I cna change and redeploy th HTTPModule dll rather
than playing with the global.asax.

Hope this helps,
Garth

"David Lozzi" wrote:
>Howdy,

I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
Kittel
and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
application level error handling. Most of my functions have try..catch to
email me about an error, then I want the application level to fire off to
send the user to a custom page AND log it in the app log. When an error
occurs on my page, i get a server error

Server Error in '/newcart' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code. Exception Details:
System.NullReferenceException: Object reference not set to an instance of
an
object.Source Error: Line 4:
Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Line 6: Throw Server.GetLastError()
Line 7: End Sub
Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
Line:
6 Any ideas?Also, I'm under the impression that if an actual error
occurs,
it will not send me to the error page as specified b/c I'm on my
development
machine. is that correct?Thanks!!-- David
Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com


Jul 20 '06 #3

P: n/a
David,
I ran a quick test and had no problem throwing the Server.GetLastError
within the Page_Error, redirection to the error page occured as expected.
I'll ask a question, and I hope I don't offend ;), have you set the mode of
your customErrors section to 'On'?
eg:
<customErrors defaultRedirect="~/Error.aspx" mode="On">
</customErrors>

If the mode is Off or RemoteOnly on your development machine you'll get the
standard server error.

As an aside, I don't normally mind the exceptions being wrapped in an
HttpUnhandledException. You can get the original exception from the
InnerException property of the unhandled exception in the application_error
event. I guess a down side (or up side depending on how you look at it) to
this is that HttpUnhandledExceptions are logged in the Application log on the
server.

Garth.
"David Lozzi" wrote:
The book states to "rethrow the last exception that occured...we do this
step to avoid having the exception information wrapped with an
HttpUnhandledException exception. ASP.NET automatically creates a new
HttpUnhandledException at the page level unless you rethrow the last
exception." sooo.....

--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com
"GarthS" <Ga****@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
David,
You shouldn't have to rethrow the sever last error in your page_error
event. As long as you don't call Server.ClearError() the
Application_Error
event should still fire and redirection to the error page should occur as
defined in your web.config.

Incidentally, I normally use the Page_Error event to perform page state
clean up and the Application_Error event in the global.asax for custom
error
handling (such as calling an EntLib exception policy - which could you
caould
configure to do your emailing and logging functions).

Depending on the deployment I sometimes use a custom HTTPModule for
hooking
in to application events. If I want to change how I'm handling an
application error then I cna change and redeploy th HTTPModule dll rather
than playing with the global.asax.

Hope this helps,
Garth

"David Lozzi" wrote:
Howdy,

I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
Kittel
and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
application level error handling. Most of my functions have try..catch to
email me about an error, then I want the application level to fire off to
send the user to a custom page AND log it in the app log. When an error
occurs on my page, i get a server error

Server Error in '/newcart' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code. Exception Details:
System.NullReferenceException: Object reference not set to an instance of
an
object.Source Error: Line 4:
Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Line 6: Throw Server.GetLastError()
Line 7: End Sub
Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
Line:
6 Any ideas?Also, I'm under the impression that if an actual error
occurs,
it will not send me to the error page as specified b/c I'm on my
development
machine. is that correct?Thanks!!-- David
Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com



Jul 20 '06 #4

P: n/a
I take great offense to the thickness of my own skull! Thank you, I'll try
that soon.
--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com
"GarthS" <Ga****@discussions.microsoft.comwrote in message
news:CB**********************************@microsof t.com...
David,
I ran a quick test and had no problem throwing the Server.GetLastError
within the Page_Error, redirection to the error page occured as expected.
I'll ask a question, and I hope I don't offend ;), have you set the mode
of
your customErrors section to 'On'?
eg:
<customErrors defaultRedirect="~/Error.aspx" mode="On">
</customErrors>

If the mode is Off or RemoteOnly on your development machine you'll get
the
standard server error.

As an aside, I don't normally mind the exceptions being wrapped in an
HttpUnhandledException. You can get the original exception from the
InnerException property of the unhandled exception in the
application_error
event. I guess a down side (or up side depending on how you look at it)
to
this is that HttpUnhandledExceptions are logged in the Application log on
the
server.

Garth.
"David Lozzi" wrote:
>The book states to "rethrow the last exception that occured...we do this
step to avoid having the exception information wrapped with an
HttpUnhandledException exception. ASP.NET automatically creates a new
HttpUnhandledException at the page level unless you rethrow the last
exception." sooo.....

--
David Lozzi
dlozzi@(remove)delphi-ts.com
www.delphi-ts.com
"GarthS" <Ga****@discussions.microsoft.comwrote in message
news:1B**********************************@microso ft.com...
David,
You shouldn't have to rethrow the sever last error in your page_error
event. As long as you don't call Server.ClearError() the
Application_Error
event should still fire and redirection to the error page should occur
as
defined in your web.config.

Incidentally, I normally use the Page_Error event to perform page state
clean up and the Application_Error event in the global.asax for custom
error
handling (such as calling an EntLib exception policy - which could you
caould
configure to do your emailing and logging functions).

Depending on the deployment I sometimes use a custom HTTPModule for
hooking
in to application events. If I want to change how I'm handling an
application error then I cna change and redeploy th HTTPModule dll
rather
than playing with the global.asax.

Hope this helps,
Garth

"David Lozzi" wrote:

Howdy,

I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
Kittel
and Geoffrey LeBlond. Anyway, they have some instructions on how to
setup
application level error handling. Most of my functions have try..catch
to
email me about an error, then I want the application level to fire off
to
send the user to a custom page AND log it in the app log. When an
error
occurs on my page, i get a server error

Server Error in '/newcart' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the
current web request. Please review the stack trace for more
information
about the error and where it originated in the code. Exception
Details:
System.NullReferenceException: Object reference not set to an instance
of
an
object.Source Error: Line 4:
Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e
As
System.EventArgs) Handles Me.Error
Line 6: Throw Server.GetLastError()
Line 7: End Sub
Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
Line:
6 Any ideas?Also, I'm under the impression that if an actual error
occurs,
it will not send me to the error page as specified b/c I'm on my
development
machine. is that correct?Thanks!!-- David
Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com




Jul 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.