473,397 Members | 1,960 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,397 software developers and data experts.

General ExceptionHandler 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Label.text = Server.GetLastError().Message()
Server.ClearError()
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 2794
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**********************************@microsof t.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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Label.text = Server.GetLastError().Message()
Server.ClearError()
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_Error 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Label.text = Server.GetLastError().Message()
Server.ClearError()
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...End 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_Error 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
Label.text = Server.GetLastError().Message()
Server.ClearError()
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
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...
4
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: ...
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...
2
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...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.