Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Exception stack is corrupt when catching and storing the exception

Reply
 
Old 03-04-2008   #1 (permalink)
Morten Herman Langkjaer


 
 

Exception stack is corrupt when catching and storing the exception

i have som code that does e number of operatoins, if any exception occurs
during the execution path, the exception is stored in a list, and in another
place, the errors are logged. for example, method a calls b, that calls c. c
throws an exception, that b stores. When using the exception.ToString(), only
method b and c appears in the stack trace. Sine the method is called from
several locations, i cannot find the execution paths without attaching a
debugger. Is this a feature/bug in the framework. Can anyone help me get the
full stack trace.

i have created a simple application that proves the problem, it is written
in C#, and is a console application. try reviewing the following:
using System;
using System.Diagnostics;

namespace testStack
{
class Program
{
static void Main(string[] args)
{
try
{
StoredErrorThrower();
}
catch( Exception e )
{
Console.Out.WriteLine();
Console.Out.WriteLine("Non stored exception stack trace");
Console.Out.WriteLine();
Console.Out.WriteLine(e);
}

Console.Out.WriteLine();
Console.Out.WriteLine();
Console.Out.WriteLine("Stored Exception stack trace:");
Console.Out.WriteLine();
Console.Out.WriteLine(error);

Console.Out.WriteLine();
Console.Out.WriteLine();
Console.Out.WriteLine("Stack frame from the stored exception handler");
Console.Out.WriteLine(frame);

}

private static void StoredErrorThrower()
{
try
{
throw new Exception("error");
}
catch( Exception e )
{
frame = new StackTrace();
error = e;
}
throw new Exception("error");
}
private static Exception error;
private static StackTrace frame;
}
}


My System SpecsSystem Spec
Old 03-05-2008   #2 (permalink)
Morten Herman Langkjaer


 
 

Re: Exception stack is corrupt when catching and storing the excep

The issue occurs in some production code, but i cant seem to reproduce the
exact error in my debug envorinment. Therefore i want to collect the errors
and then log them afterwards. But i can't seem to have full stack trace
logged, unless i create a new instance of the StackTrace class, bu sincte the
exceptions are a part of the public interface, i cannot just introduce the
combination of StackTrace and Exception without changing the interface.
Therefore i would like to know if there is any way to change the way .NET
calculate the stackTrace to enable full stack logging always.

"dlm@xxxxxx" wrote:
Quote:

> Hi Morten,
>
> have you tried to get full stack, debugging your code with SOS extensions enabled? With stack related commands (!clrstack, !dumpstack, !clrstack -p, !clrstack -l) you should get full picture of what's going on.
>
> Best regards,
> dlm@xxxxxx
> Compare SQL Server, MySQL and Oracle for free - DBTyP.NET
> www.bypsoft.com
>
>
> "Morten Herman Langkjaer" <MortenHermanLangkjaer@xxxxxx> schrieb im Newsbeitrag news:7F737C3F-F4A2-4389-86A9-9C67D383006F@xxxxxx
Quote:

> >i have som code that does e number of operatoins, if any exception occurs
> > during the execution path, the exception is stored in a list, and in another
> > place, the errors are logged. for example, method a calls b, that calls c. c
> > throws an exception, that b stores. When using the exception.ToString(), only
> > method b and c appears in the stack trace. Sine the method is called from
> > several locations, i cannot find the execution paths without attaching a
> > debugger. Is this a feature/bug in the framework. Can anyone help me get the
> > full stack trace.
> >
> > i have created a simple application that proves the problem, it is written
> > in C#, and is a console application. try reviewing the following:
> > using System;
> > using System.Diagnostics;
> >
> > namespace testStack
> > {
> > class Program
> > {
> > static void Main(string[] args)
> > {
> > try
> > {
> > StoredErrorThrower();
> > }
> > catch( Exception e )
> > {
> > Console.Out.WriteLine();
> > Console.Out.WriteLine("Non stored exception stack trace");
> > Console.Out.WriteLine();
> > Console.Out.WriteLine(e);
> > }
> >
> > Console.Out.WriteLine();
> > Console.Out.WriteLine();
> > Console.Out.WriteLine("Stored Exception stack trace:");
> > Console.Out.WriteLine();
> > Console.Out.WriteLine(error);
> >
> > Console.Out.WriteLine();
> > Console.Out.WriteLine();
> > Console.Out.WriteLine("Stack frame from the stored exception handler");
> > Console.Out.WriteLine(frame);
> >
> > }
> >
> > private static void StoredErrorThrower()
> > {
> > try
> > {
> > throw new Exception("error");
> > }
> > catch( Exception e )
> > {
> > frame = new StackTrace();
> > error = e;
> > }
> > throw new Exception("error");
> > }
> > private static Exception error;
> > private static StackTrace frame;
> > }
> > }
> >
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Exception PowerShell
.net security exception .NET General
SqlClientPermission exception .NET General
Vista Install Error: Exception Unknown Software Exception Vista installation & setup
Unhandled exception at 0x779447f2 in explorer.exe: 0xC00000FD: Stack overflow. Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46