By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

General ExceptionHandler in Asp.Net - Page_Error?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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 im trying to do?

Nov 19 '05 #2

P: n/a
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 im trying to do?


Nov 19 '05 #3

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.