473,320 Members | 2,048 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,320 software developers and data experts.

Can't get exception stack

Hi;

I have added the code to my code behinds of:
private void Page_Error(object sender, EventArgs e)
{
throw Server.GetLastError();
}

But I now have the problem that the call stack I get is to Page_Error. I
need the call stack of the exception that got me to this point. How can I get
that to log?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Sep 15 '06 #1
5 1639
You can make a call to Server.GetLastError().GetBaseException() in your
Global.asax Application_Errror handler. If desired, you can log this
exception and then call Server.ClearError()

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"David Thielen" wrote:
Hi;

I have added the code to my code behinds of:
private void Page_Error(object sender, EventArgs e)
{
throw Server.GetLastError();
}

But I now have the problem that the call stack I get is to Page_Error. I
need the call stack of the exception that got me to this point. How can I get
that to log?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Sep 15 '06 #2
That still has the end of the stack trace coming from the Page_Error method.
But if I delete the Page_Error method and if the exception is a
HttpUnhandledException I get it's InnerException, then it works fine.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Peter Bromberg [C# MVP]" wrote:
You can make a call to Server.GetLastError().GetBaseException() in your
Global.asax Application_Errror handler. If desired, you can log this
exception and then call Server.ClearError()

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"David Thielen" wrote:
Hi;

I have added the code to my code behinds of:
private void Page_Error(object sender, EventArgs e)
{
throw Server.GetLastError();
}

But I now have the problem that the call stack I get is to Page_Error. I
need the call stack of the exception that got me to this point. How can I get
that to log?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Sep 15 '06 #3
Hello Dave,

Are you going to use the Page_Error event to get the unhandled exception in
page and log it? Based on my understanding, we can use the
Server.GetLastError to obtain the original unhandled exception in ASP.NET
page's process request.(in Page_Error or application_Error event).

From the code you provided, I'm wondering why you rethrow the original
exception in Page_Error event handler as below:

==================
private void Page_Error(object sender, EventArgs e)
{
throw Server.GetLastError();
}
==================

this will cause the Server's LastError be replaced by this exception and
the callstack is replaced by the new one(from Page_Error instead of the
original exception).

I've performed test through the following code:

=========================
protected void Page_Error(object sender, EventArgs e)
{
Response.Write("<br/>" + Server.GetLastError().StackTrace);
Response.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
throw new Exception("test page exception..........");
}
=========================

and the Page_Error can correctly get the exception callstack of the one
throwed in the Button1_click.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 18 '06 #4
Hi;

I amy be approaching this wrong. What I want is all exceptions to go to
error.aspx & error.aspx.cs. In the code-behind I log the error with the stack
trace. I took this approach as it puts all of the error handling in a single
place.

Once I removed the Page_Error method and look at InnerException if it was
wrapped ain a Http???Exception, it all seesm to work the way I want.

Is there a better way to do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm


"Steven Cheng[MSFT]" wrote:
Hello Dave,

Are you going to use the Page_Error event to get the unhandled exception in
page and log it? Based on my understanding, we can use the
Server.GetLastError to obtain the original unhandled exception in ASP.NET
page's process request.(in Page_Error or application_Error event).

From the code you provided, I'm wondering why you rethrow the original
exception in Page_Error event handler as below:

==================
private void Page_Error(object sender, EventArgs e)
{
throw Server.GetLastError();
}
==================

this will cause the Server's LastError be replaced by this exception and
the callstack is replaced by the new one(from Page_Error instead of the
original exception).

I've performed test through the following code:

=========================
protected void Page_Error(object sender, EventArgs e)
{
Response.Write("<br/>" + Server.GetLastError().StackTrace);
Response.End();
}
protected void Button1_Click(object sender, EventArgs e)
{
throw new Exception("test page exception..........");
}
=========================

and the Page_Error can correctly get the exception callstack of the one
throwed in the Button1_click.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 18 '06 #5
Hello Dave,

If you want to get all the unhandled exceptions, the global.asax's
Application_Error event should be more appropriate or you just want to
capture the exceptions at a certain page?

As you said you want to redirect the user to a error.aspx page and display
the error, you can consider use the Server.Transfer to forward the current
request to the error page and use Server.GetLastError to get the exception.
e.g.:

=====in problem page===========

public partial class _Default : System.Web.UI.Page
{
........................
protected void Button1_Click(object sender, EventArgs e)
{
Exception ex = new Exception("test exception...........");

throw ex;
}
protected void Page_Error(object sender, EventArgs e)
{
Server.Transfer("~/error.aspx");
}
}
======in error.aspx page===========
public partial class error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();

Response.Write("<br/>Server Error:<br/>" + ex.ToString());

}
}
===============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 19 '06 #6

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

Similar topics

42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
4
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
4
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks...
10
by: Neelesh Bodas | last post by:
Hi all, suppose the ctor of the class throws. Thus, at this point in time, some memory has been allocated but the object couldnot be constructed. Also, the memory is not yet freed. Does the c++...
1
by: Modica82 | last post by:
I have created a contract first web service, and to test i have created a client (asp.net) to attempt to test that my web service is at least communication. But when i call a method i get the...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
4
by: Tony | last post by:
Well the subject says it all. Do I have to have it if I use classes in C++? Tony
3
by: George2 | last post by:
Hello everyone, Suppose I have some objects created on local function stack (not on heap). And I allocate and free all the related resources in the constructor and destructor (e.g. memory and...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
1
by: tshad | last post by:
If I do a: throw(new Exception("This is an error")); This gets handled correctly, but there is no stack information here. Why is that? Thanks,
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.