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

error trapping question

Tom
On my web app (.net 05) I created a generic error handler class, now I want
to be able to pass the error (from any page) to this class, then redirect the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?

Jul 26 '06 #1
2 1196
Put the following code in either your page, or in a base page class which
all your pages inherit from.
You would need to replace "ex.aspx" with the name of your error page, and
the Response.Redirect,
you would need to replace the argument with the path to your error page.

Where i have LastException = Server.GetLastError(), you could replace that
with any code you want.

In my base page class LastException is a protected property of type
Exception which simply wraps
a session variable. So i set this, then redirect to my exception page
(ex.aspx) which then takes care of
emailing or logging the exception, and displaying an appropriate message to
the user.

#Region " Page_Error "
Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
LastException = Server.GetLastError

If Me.PageNameFile <"ex.aspx" Then Response.Redirect("~/ex.aspx")
End Sub
#End Region

"Tom" <To*@discussions.microsoft.comwrote
On my web app (.net 05) I created a generic error handler class, now I
want
to be able to pass the error (from any page) to this class, then redirect
the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?

Jul 26 '06 #2
Tom
thanks, I actually put the redirect in the web.config file, and I'm passing
the error to my error class and logging it via a log file.

thanks

"Arthur Dent" wrote:
Put the following code in either your page, or in a base page class which
all your pages inherit from.
You would need to replace "ex.aspx" with the name of your error page, and
the Response.Redirect,
you would need to replace the argument with the path to your error page.

Where i have LastException = Server.GetLastError(), you could replace that
with any code you want.

In my base page class LastException is a protected property of type
Exception which simply wraps
a session variable. So i set this, then redirect to my exception page
(ex.aspx) which then takes care of
emailing or logging the exception, and displaying an appropriate message to
the user.

#Region " Page_Error "
Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
LastException = Server.GetLastError

If Me.PageNameFile <"ex.aspx" Then Response.Redirect("~/ex.aspx")
End Sub
#End Region

"Tom" <To*@discussions.microsoft.comwrote
On my web app (.net 05) I created a generic error handler class, now I
want
to be able to pass the error (from any page) to this class, then redirect
the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?


Jul 26 '06 #3

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

Similar topics

8
by: Pete | last post by:
I'm trying to improve my code so that when I open a recordset object, I can absolutely guarantee it is closed and is set = Nothing. I have read some old threads and they all say to use the...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
3
by: windandwaves | last post by:
Hi Gurus Does anyone know how I set the error trapping to option 2 in visual basic. I know that you can go to tools, options and then choose on unhandled errors only, but is there a VB command...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.