Question

i am developing my own automated bug reporting system for my project, what i want to know is is there a way to get the stack trace of my program when an exception is thrown, i know how to get the full stack trace to a file but in my case i need to catch the stack trace only for the exception (stack trace that is only relevant to the exception), please direct me. if there is any code sample, it would be grate!

code i used to get the stack trace is below

            StackTrace st = new StackTrace();
            richTextBox1.Text = st.ToString();

thanx in adavance! i am using below technologies in my project c#, .net 4.0.

Was it helpful?

Solution

The Exception object itself has a StackTrace property you can use to get the stack trace for the exception when it is caught.

try
{
   // code
}
catch (Exception ex)
{
   richTextBox1.Text = ex.StackTrace;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top