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

Page_Error not working !?

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:

---------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim txtTextBox As TextBox
txtTextBox.Text = "A"
End Sub

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Error: ")
Response.Write("<p></p>")
Response.Write(Server.GetLastError.Message)
Server.ClearError()
End Sub
---------------------------------------------------------------------------------

I see "Object reference not set to an instance of an object" in the default
ASP.NET error page....
I have played with Debug=true/false, trace=True/False, <customErrors
mode="On/Off/RemoteOnly" />, etc, but to no avail.

Please, what am I missing here ?

Thank you, Alex.
Nov 19 '05 #1
4 6197
Hi,

the Page_Error event is indeed firing and the handling code is also
executing. Tyr setting autoeventwireup = "false" and set breakpoints to the
Page_error handler to see whether that piece is executing or not.

regards
Joyjit

"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message
news:O1****************@tk2msftngp13.phx.gbl...
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:

-------------------------------------------------------------------------- ------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim txtTextBox As TextBox
txtTextBox.Text = "A"
End Sub

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Error: ")
Response.Write("<p></p>")
Response.Write(Server.GetLastError.Message)
Server.ClearError()
End Sub
-------------------------------------------------------------------------- -------
I see "Object reference not set to an instance of an object" in the default ASP.NET error page....
I have played with Debug=true/false, trace=True/False, <customErrors
mode="On/Off/RemoteOnly" />, etc, but to no avail.

Please, what am I missing here ?

Thank you, Alex.

Nov 19 '05 #2
Hi Alex,

You're missing this in your Page_Load sub:

AddHandler Page.Error, AddressOf Page_Error

But I believe it only catches *server* errors (IIS), not *your
application* errors. That's why Server.GetLastError() is always empty
(Nothing), and your sub doesn't fire. To catch Application errors, I
think you must use either try/catch blocks, or the Application_Error
sub in Global.asax.vb...

HTH,

Michel

"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message news:<O1**************@tk2msftngp13.phx.gbl>...
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:

---------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim txtTextBox As TextBox
txtTextBox.Text = "A"
End Sub

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Error: ")
Response.Write("<p></p>")
Response.Write(Server.GetLastError.Message)
Server.ClearError()
End Sub
---------------------------------------------------------------------------------

I see "Object reference not set to an instance of an object" in the default
ASP.NET error page....
I have played with Debug=true/false, trace=True/False, <customErrors
mode="On/Off/RemoteOnly" />, etc, but to no avail.

Please, what am I missing here ?

Thank you, Alex.

Nov 19 '05 #3
You will need to handle the Error event.

Try adding Handles MyBase.Error to yous Page_Error sub.

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Error.

This Page.Error event is triggered when an unhandled exception occurs
anywhere during page processing. The Application.Error will fire when
outside of the scope of a page.

Try this out and let us know how it resolved out.

Here is the stub I used to test it out.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Throw New Exception("Exception Thrown")
End Sub

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error
Dim exception As Exception
exception = Server.GetLastError()
Response.Write(exception.Message)
Server.ClearError()
End Sub

bill
"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message
news:O1****************@tk2msftngp13.phx.gbl...
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:

-------------------------------------------------------------------------- ------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim txtTextBox As TextBox
txtTextBox.Text = "A"
End Sub

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Error: ")
Response.Write("<p></p>")
Response.Write(Server.GetLastError.Message)
Server.ClearError()
End Sub
-------------------------------------------------------------------------- -------
I see "Object reference not set to an instance of an object" in the default ASP.NET error page....
I have played with Debug=true/false, trace=True/False, <customErrors
mode="On/Off/RemoteOnly" />, etc, but to no avail.

Please, what am I missing here ?

Thank you, Alex.

Nov 19 '05 #4
Thank you all - problem solved ! :-)))

Alex.

"Alex Nitulescu" <RE***********************@yahoo.com> wrote in message
news:O1****************@tk2msftngp13.phx.gbl...
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:

---------------------------------------------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim txtTextBox As TextBox
txtTextBox.Text = "A"
End Sub

Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Response.Write("Error: ")
Response.Write("<p></p>")
Response.Write(Server.GetLastError.Message)
Server.ClearError()
End Sub
---------------------------------------------------------------------------------

I see "Object reference not set to an instance of an object" in the
default ASP.NET error page....
I have played with Debug=true/false, trace=True/False, <customErrors
mode="On/Off/RemoteOnly" />, etc, but to no avail.

Please, what am I missing here ?

Thank you, Alex.

Nov 19 '05 #5

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

Similar topics

2
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
2
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...
1
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....
2
by: Carl Johansen | last post by:
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...
6
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
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...
0
by: slolife | last post by:
What I am trying to do is handle the HttpRequestValidationException with code, but only on pages that are equipped to handle it with special customvalidators, controls, etc.. But what I cannot...
3
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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
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...
0
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,...

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.