StackTrace

  • Thread starter Thread starter Nenad Dobrilovic
  • Start date Start date
N

Nenad Dobrilovic

Hi,
As I can see, Compact Framework has no System.Environment.StackTrace.
Is there any other way to find out stack trace when I catch exception?
Thanx in advance,
Cheya
 
Cheya,

There is no assembly to do this for you, but if you take the time to
iterate through the exception object's error parameters and log/display the
values, you can often get more information than even a stack trace
would give you. Below is an example from the .Net CF Core Reference
provided for a SqlCE exception. I have created similar methods for Web
exceptions, I/O exceptions, etc. If you ever run a debug session and start
drilling down through the nexted levels of exception parameters, there is
a host of valuable information in this heirarchy that you can use to
troubleshoot
your application.

private void _displaySQLCEErrors(SqlCeException ex)
{
SqlCeErrorCollection errorCollection = ex.Errors;

StringBuilder bld = new StringBuilder();
Exception inner = ex.InnerException;

foreach (SqlCeError err in errorCollection)
{
bld.Append("\n Error Code: " + err.HResult.ToString("X"));
bld.Append("\n Message : " + err.Message);
bld.Append("\n Minor Err.: " + err.NativeError);
bld.Append("\n Source : " + err.Source);

foreach (int numPar in err.NumericErrorParameters)
{
if ( 0 != numPar ) bld.Append( "\n Num. Par. : " + numPar );
}

foreach ( string errPar in err.ErrorParameters )
{
if ( String.Empty != errPar ) bld.Append( "\n Err. Par. : " + errPar );
}

MessageBox.Show( bld.ToString(), "SQL Server CE Error" );
bld.Remove(0, bld.Length);
}
}

-Darren
 
Darren said:
MessageBox.Show( bld.ToString(), "SQL Server CE Error" );
bld.Remove(0, bld.Length);

I have to admit I'm a bit curious as of the purpose of the last line
 
Alex,

This method came out of The Core Reference samples - it's been sitting in my
personal DatabaseManager class for 2 years now and I never really looked
all that closely at it since it never makes it into production builds (debug
only).

I think the intention was to save StringBuilder creation by instantiating a
single
StringBuilder and reusing by clearing it's contents each time a new
error parameter is dumped as the loop executes.

-Darren
 
If you can afford (in your debugging) not to catch/trap the exception - you
will get Exception Dialog Box which will contain the call stack at the
momemt of exception.

Pavel Treskunov
..NET Compact Framework
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 
Back
Top