473,804 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

General ExceptionHandle r in Asp.Net - Page_Error?

Hi!
I want to set up an exception handler in my asp.net page which handles all
unhandled exception. When the exception is trapped I want to assign its
message to a label. How can I do this?

I have tryied to do like this:

Protected Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Error
Label.text = Server.GetLastE rror().Message( )
Server.ClearErr or()
End Sub

The exception is trapped but I got a blank page. Why is that? Is it
possible to do what i´m trying to do?
Nov 19 '05 #1
3 2810
Hi,

the problem most likely is that the error causes the page to stop the
execution and just to raise the error handler up (processing does not
continue to rendering etc), therefore it is visible like this.

If you want to let the execution continue, you'd need to catch exceptions at
blobk/method level.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Clas" <no****@co.se > wrote in message
news:AA******** *************** ***********@mic rosoft.com...
Hi!
I want to set up an exception handler in my asp.net page which handles all
unhandled exception. When the exception is trapped I want to assign its
message to a label. How can I do this?

I have tryied to do like this:

Protected Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Error
Label.text = Server.GetLastE rror().Message( )
Server.ClearErr or()
End Sub

The exception is trapped but I got a blank page. Why is that? Is it
possible to do what i´m trying to do?

Nov 19 '05 #2
Well, I'm not sure why your Label isn't working, but I do have a comment
about the approach in general. Once this goes to production, I'd suggest
not doing this. The reason is that you shouldn't show exception information
to an end user. If the end user is an attacker (malicious) then they can
use that information against you. Instead, you should only ever show vague
information that "there was some sort of problem". Of course, log that in
your global.asax's Application_Err or method so an admin has all the info,
but don't give it to your users.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi!
I want to set up an exception handler in my asp.net page which handles
all
unhandled exception. When the exception is trapped I want to assign
its
message to a label. How can I do this?
I have tryied to do like this:

Protected Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Error
Label.text = Server.GetLastE rror().Message( )
Server.ClearErr or()
End Sub
The exception is trapped but I got a blank page. Why is that? Is it
possible to do what i´m trying to do?


Nov 19 '05 #3
Hi, I would try doing a Try...Catch...E nd Try method. your catch could be:

cath e as exception
label.text ="text"
"Brock Allen" wrote:
Well, I'm not sure why your Label isn't working, but I do have a comment
about the approach in general. Once this goes to production, I'd suggest
not doing this. The reason is that you shouldn't show exception information
to an end user. If the end user is an attacker (malicious) then they can
use that information against you. Instead, you should only ever show vague
information that "there was some sort of problem". Of course, log that in
your global.asax's Application_Err or method so an admin has all the info,
but don't give it to your users.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi!
I want to set up an exception handler in my asp.net page which handles
all
unhandled exception. When the exception is trapped I want to assign
its
message to a label. How can I do this?
I have tryied to do like this:

Protected Sub Page_Error(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Error
Label.text = Server.GetLastE rror().Message( )
Server.ClearErr or()
End Sub
The exception is trapped but I got a blank page. Why is that? Is it
possible to do what i´m trying to do?


Nov 19 '05 #4

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

Similar topics

2
4130
by: Tee | last post by:
what's the differences between "Overrides Sub OnError" and "Sub Page_Error" ?
2
2810
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 :
4
6231
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: --------------------------------------------------------------------------------- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
1
3712
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
2125
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
4573
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
2133
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?
2
1309
by: Eric Sabine | last post by:
I built a generic exception handler form which allows the user to get information from it, print it, email it, etc. for exceptions for which I explicitly didn't handle in code, such as missing permissions on a stored procedure, etc. I use this exception handler in all of my applications and it can be called as simply as follows try ... catch ex as sqlexception ExceptionHandler(ex, otherData1, otherData2)
2
1453
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
9705
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
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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
10323
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
10311
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
9138
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
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
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.