473,406 Members | 2,710 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,406 software developers and data experts.

Error Handleing at the Application Level Server Error

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
4 2157
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
4
by: tommy | last post by:
hello everbody, i write a little asp-application with forms-authentication. i copy my aspx-files with web.config to my webspace and i get the error above... i tried to set the...
12
by: Brett Robichaud | last post by:
Is anyone familiar with this error? I have this running just fine on my local machine but when I pushed it out to our development server I get this error. I have no idea what it is saying. Any...
3
by: Sean | last post by:
HI There, I am having trouble deploying my .aspx pages to a remote server, I have made changes to the config file and it still returns an error. I have also contacted the server administrator to...
2
by: news.microsoft.com | last post by:
hi, I am new in ASP.NET i make a page using Visual Studio.net compile and successfully run on local system but when i upload it on my internet live server it always gives me the same error if...
0
by: Adam Getchell | last post by:
I'm attempting to write a custom Authentication module using http://www.15seconds.com/Issue/020417.htm I looked at http://support.microsoft.com/default.aspx?scid=kb;EN-US;307996, but it doesn't...
6
by: chokk | last post by:
All, I am getting the following error when I try to run a form page. Can someone tell me what this is about and show me how to fix it. Thnaks. Server Error in '/' Application...
1
by: Ramanfromoz | last post by:
Hi, Developing a new we application. Everything okay on my local WIN XP PROFESSIONAL, IIS 5.0 running locally. The website is running smoothly. Now, the same code I am copying over to a...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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...
0
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
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...

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.