Hello is there a class that does a pretty conversion?
Using printStackTrace() method − It print the name of the exception, description and complete stack trace including the line where exception occurred. Using toString() method − It prints the name and description of the exception. Using getMessage() method − Mostly used. It prints the description of the exception.
A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.
If you want to save a stack trace for later use or create a link to it, click the Share button store the stack trace. Sharing stack traces on elmah.io works pretty much like gists on GitHub, but are nicely formatted and provides the visitor of your stack trace with the options for copying and saving a stack trace.
There isn't anything built in, but it would be fairly easy.
Just grab the StackTrace:
// Create trace from exception
var trace = new System.Diagnostics.StackTrace(exception);
// or for current code location
var trace = new System.Diagnostics.StackTrace(true);
Once you have this, just iterate the stack frames, and format them as desired.
There would be lots of ways to format this into HTML - it really depends on how you want it to look. The basic concept would be:
int frameCount = trace.Framecount;
for (int i=0;i<frameCount;++i)
{
var frame = trace.GetFrame(i);
// Write properties to formatted HTML, including frame.GetMethod()/frame.GetFileName(), etc.
// The specific format is really up to you.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With