473,651 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page_Error not working !?

Hi.

I read about Page_Error and Application_Err or. 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.EventArg s) Handles MyBase.Load

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

Sub Page_Error(ByVa l sender As Object, ByVal e As EventArgs)
Response.Write( "Error: ")
Response.Write( "<p></p>")
Response.Write( Server.GetLastE rror.Message)
Server.ClearErr or()
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 6222
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************ ***********@yah oo.com> wrote in message
news:O1******** ********@tk2msf tngp13.phx.gbl. ..
Hi.

I read about Page_Error and Application_Err or. 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.EventArg s) Handles MyBase.Load

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

Sub Page_Error(ByVa l sender As Object, ByVal e As EventArgs)
Response.Write( "Error: ")
Response.Write( "<p></p>")
Response.Write( Server.GetLastE rror.Message)
Server.ClearErr or()
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.GetLastE rror() 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_Err or
sub in Global.asax.vb. ..

HTH,

Michel

"Alex Nitulescu" <RE************ ***********@yah oo.com> wrote in message news:<O1******* *******@tk2msft ngp13.phx.gbl>. ..
Hi.

I read about Page_Error and Application_Err or. 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.EventArg s) Handles MyBase.Load

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

Sub Page_Error(ByVa l sender As Object, ByVal e As EventArgs)
Response.Write( "Error: ")
Response.Write( "<p></p>")
Response.Write( Server.GetLastE rror.Message)
Server.ClearErr or()
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(ByVa l 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.Err or 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.EventArg s) Handles MyBase.Load
Throw New Exception("Exce ption Thrown")
End Sub

Private Sub Page_Error(ByVa l sender As Object, ByVal e As System.EventArg s)
Handles MyBase.Error
Dim exception As Exception
exception = Server.GetLastE rror()
Response.Write( exception.Messa ge)
Server.ClearErr or()
End Sub

bill
"Alex Nitulescu" <RE************ ***********@yah oo.com> wrote in message
news:O1******** ********@tk2msf tngp13.phx.gbl. ..
Hi.

I read about Page_Error and Application_Err or. 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.EventArg s) Handles MyBase.Load

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

Sub Page_Error(ByVa l sender As Object, ByVal e As EventArgs)
Response.Write( "Error: ")
Response.Write( "<p></p>")
Response.Write( Server.GetLastE rror.Message)
Server.ClearErr or()
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************ ***********@yah oo.com> wrote in message
news:O1******** ********@tk2msf tngp13.phx.gbl. ..
Hi.

I read about Page_Error and Application_Err or. 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.EventArg s) Handles MyBase.Load

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

Sub Page_Error(ByVa l sender As Object, ByVal e As EventArgs)
Response.Write( "Error: ")
Response.Write( "<p></p>")
Response.Write( Server.GetLastE rror.Message)
Server.ClearErr or()
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
4121
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
2
2801
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 label contained in a user control from these events : "lbl_error" is the ID of my label :
1
3702
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. The problem is that the page does not render. I either get a "Document Contains No Data" message or the browsers just sits there loading for what appears to al eternity. Here's the Page_Error procedure: Sub Page_Error(ByVal sender As...
2
2112
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 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...
6
4554
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 if you are already capturing errors in Application_Error? Also, if you have any links to discussions about when to use which function it would be helpful.
2
2122
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 vise-versa? Or is it just a matter of handling the same exact thing in different scopes?
0
1170
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 seem to find is where to put some code in my derived page that sets a property in the base page class that tells the base Page_Error to deal with HttpRequestValidationException. See the code below. Here's my base page:
3
1260
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 file. I would like to have inline Page_Error methods for certain pages, particularly some XML exchanges I have in place for some AJAX functionality. Thx for any info, Carlo
2
1440
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 EventArgs) Handles MyBase.Error Dim e As System.Exception = Server.GetLastError() Session("Erro")= "Error: " & e.Message.ToString() & "<p>Stack Trace: " & e.StackTrace.ToString() Context.ClearError()
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8803
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8581
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7298
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.