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

Error-handling

Hi all,

If an error occurs in an aspx-page, you can configure the web.config in a
way that the user automatically navigates to a certain page (e.g.
error.aspx).

My question: is it possible to catch the stacktrace of the error in
error.aspx so it can be logged? The error has been catched somewhere in
order to perform the reroute to error.aspx. So where are the error-details?

Leo R.
Nov 17 '05 #1
6 1362
The Error information is contained in the Exception that is thrown, which is
an object. Here is a sample of an Error Handler that I use frequently. The
reference to the "LogError()" method would be whatever you want to do with
your Exception data:

public static void HandleError(Exception e)
{
try
{
StringBuilder strMessage = new StringBuilder(e.Message);
if (e.InnerException != null)
strMessage.Append(Environment.NewLine + "Inner Exception: " +
e.InnerException.Message);
strMessage.Append(Environment.NewLine + "StackTrace: " + Environment.NewLine
+ e.StackTrace);
LogError(strMessage.ToString());
}
catch {}
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Leo R" <no****@newsgroups.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Hi all,

If an error occurs in an aspx-page, you can configure the web.config in a
way that the user automatically navigates to a certain page (e.g.
error.aspx).

My question: is it possible to catch the stacktrace of the error in
error.aspx so it can be logged? The error has been catched somewhere in
order to perform the reroute to error.aspx. So where are the error-details?
Leo R.

Nov 17 '05 #2
The Error information is contained in the Exception that is thrown, which is
an object. Here is a sample of an Error Handler that I use frequently. The
reference to the "LogError()" method would be whatever you want to do with
your Exception data:

public static void HandleError(Exception e)
{
try
{
StringBuilder strMessage = new StringBuilder(e.Message);
if (e.InnerException != null)
strMessage.Append(Environment.NewLine + "Inner Exception: " +
e.InnerException.Message);
strMessage.Append(Environment.NewLine + "StackTrace: " + Environment.NewLine
+ e.StackTrace);
LogError(strMessage.ToString());
}
catch {}
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Leo R" <no****@newsgroups.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Hi all,

If an error occurs in an aspx-page, you can configure the web.config in a
way that the user automatically navigates to a certain page (e.g.
error.aspx).

My question: is it possible to catch the stacktrace of the error in
error.aspx so it can be logged? The error has been catched somewhere in
order to perform the reroute to error.aspx. So where are the error-details?
Leo R.

Nov 17 '05 #3
Kevin,

Thanks for your reply. I understand how to catch an error. What I mean is:

An error is thrown in a certain aspx-page; let's say page1.aspx. As a result
of the Web.config seting for errors the user is redirected to error.aspx
because of the (unhandled) error in page1.aspx. I want to process the
stacktrace of the error that was thrown in the page1.aspx or any other page
in my webapplication in the page 'error.aspx'.

The reason why is that I don't want to put try catch blocks in all my
aspx-pages. Is that possible?

Leo R.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
The Error information is contained in the Exception that is thrown, which is an object. Here is a sample of an Error Handler that I use frequently. The
reference to the "LogError()" method would be whatever you want to do with
your Exception data:

public static void HandleError(Exception e)
{
try
{
StringBuilder strMessage = new StringBuilder(e.Message);
if (e.InnerException != null)
strMessage.Append(Environment.NewLine + "Inner Exception: " +
e.InnerException.Message);
strMessage.Append(Environment.NewLine + "StackTrace: " + Environment.NewLine + e.StackTrace);
LogError(strMessage.ToString());
}
catch {}
}

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Leo R" <no****@newsgroups.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Hi all,

If an error occurs in an aspx-page, you can configure the web.config in a way that the user automatically navigates to a certain page (e.g.
error.aspx).

My question: is it possible to catch the stacktrace of the error in
error.aspx so it can be logged? The error has been catched somewhere in
order to perform the reroute to error.aspx. So where are the

error-details?

Leo R.


Nov 17 '05 #4
Hi Leo,

Based on my research and experience, I don't think that what you want to do
is possible. The reasons is "...Once the redirect is done, your error
information is no longer available on the redirected page...". Please refer
to the following article for the detailed information.

Web Application Error Handling in ASP.NET
http://www.15seconds.com/issue/030102.htm

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5
If you use the code I gave you and then throw the exception (in your catch
block) afterwards it will work as you wish.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Leo R" <no****@newsgroups.com> wrote in message
news:Oi**************@TK2MSFTNGP12.phx.gbl...
Kevin,

Thanks for your reply. I understand how to catch an error. What I mean is:

An error is thrown in a certain aspx-page; let's say page1.aspx. As a result of the Web.config seting for errors the user is redirected to error.aspx
because of the (unhandled) error in page1.aspx. I want to process the
stacktrace of the error that was thrown in the page1.aspx or any other page in my webapplication in the page 'error.aspx'.

The reason why is that I don't want to put try catch blocks in all my
aspx-pages. Is that possible?

Leo R.

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:e0**************@tk2msftngp13.phx.gbl...
The Error information is contained in the Exception that is thrown, which
is
an object. Here is a sample of an Error Handler that I use frequently. The reference to the "LogError()" method would be whatever you want to do with your Exception data:

public static void HandleError(Exception e)
{
try
{
StringBuilder strMessage = new StringBuilder(e.Message);
if (e.InnerException != null)
strMessage.Append(Environment.NewLine + "Inner Exception: " +
e.InnerException.Message);
strMessage.Append(Environment.NewLine + "StackTrace: " + Environment.NewLine
+ e.StackTrace);
LogError(strMessage.ToString());
}
catch {}
}

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Leo R" <no****@newsgroups.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Hi all,

If an error occurs in an aspx-page, you can configure the web.config in a way that the user automatically navigates to a certain page (e.g.
error.aspx).

My question: is it possible to catch the stacktrace of the error in
error.aspx so it can be logged? The error has been catched somewhere

in order to perform the reroute to error.aspx. So where are the

error-details?

Leo R.



Nov 17 '05 #6
Hi Leo,

Firstly I want to thank Kevin for his great help in this issue.

If you want to do something before error processing goes to the
customErrors setup in the web.config file, you should either hook the the
Page_Error or override the OnError sub. For example,

Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Error

End Sub

Or you can use this one:

Protected Overrides Sub OnError(ByVal e As System.EventArgs)
End Sub

For more info, please refer to the following Knowledge base article which I
have mentioned before

Web Application Error Handling in ASP.NET
http://www.15seconds.com/issue/030102.htm

I hope it helps.

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
0
by: mchuc7719 | last post by:
Hello, I have a Vb.Net 2005 ClassLibrary, when I try to compile using MSBee, only get errors. Before I to run the command line, I open in notepad the .vbproj and I was add the next line: ...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
4
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.