Skip to main content
A newer version of this page is available. .
All docs
V21.2

Obtain an Exception's Call Stack

  • 2 minutes to read

This article explains how to get an exception’s call stack. This may be useful when you need to inform DevExpress Support about a problem that occurs at runtime and which you cannot reproduce step-by-step.

Get Exception Call Stack

Follow the steps below to catch user-handled exceptions.

  1. In the VS Tools | Options… dialog, go to the Debugging node and uncheck the Enable Just My Code (Managed Only) check box.
  2. Select the Debug | Windows | Exception Settings menu item or press Ctrl+Alt+E. The Exceptions dialog appears.
  3. Select the “Common Language Runtime Exceptions“ item.
  4. Reproduce the problem and open the Call Stack window (Debug | Windows | Call Stack).
  5. Select all text in the Call Stack window. Press Ctrl+C to copy the stack trace to the clipboard.
  6. Send the stack trace to DevExpress Support.

Refer to thew following article for more information: Manage exceptions with the debugger in Visual Studio.

Get Exception Call Stack in Multiple Threads

When an exception relates to cross-thread communications, it is necessary to analyze stack traces in all threads. To obtain this information, click the Debug | Windows | Threads menu item. In the Threads window, click the Expand callstacks item in the toolbar, select and copy all lines.

exception callstack expand callstacks

Get Exception Call Stack on an End-User Machine

If the exception occurs on your end user’s machine (or anytime when it is impossible to attach a debugger to the application to obtain the call stack), you can handle the FirstChanceException event and save the exception’s call stack programmatically.

The code sample below illustrates how to save the log file to an end user’s desktop.

// Place this code to the Main() method in your application.
AppDomain.CurrentDomain.FirstChanceException += (sender, e) => {
     System.Text.StringBuilder msg = new System.Text.StringBuilder();
     msg.AppendLine(e.Exception.GetType().FullName);
     msg.AppendLine(e.Exception.Message);
     System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
     msg.AppendLine(st.ToString());
     msg.AppendLine();
     String desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     string logFilePath = String.Format("{0}\\{1}",desktopPath,"logfile.txt");
     System.IO.File.AppendAllText(logFilePath, msg.ToString());
 };
See Also