48

Possible Duplicate:
How to print the current Stack Trace in .NET without any exception?

When an exception is thrown, its text contains the stack trace. Can I somehow obtain the stack trace text(including file and line) without exceptions?

public void f()
{
   //blah
   string stacktrace = ???;
   //blah
}
0

3 Answers 3

88

Environment.StackTrace or System.Diagnostics.StackTrace if you need a more convenient (i.e. not string) representation

Sign up to request clarification or add additional context in comments.

Comments

23

Yes ...

StackTrace stackTrace = new StackTrace();           // get call stack
StackFrame[] stackFrames = stackTrace.GetFrames()

Comments

15
string stackTrace = Environment.StackTrace;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.