generalinformation-403685-support-services-obtain-exception-call-stack.md
This article explains how to get an exception’s call stack in Visual Studio. 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.
Follow the steps below to catch user-handled exceptions in Visual Studio.
Refer to thew following article for more information: Manage exceptions with the debugger in Visual Studio.
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.
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());
};
' Place this code to the Main() method in your application.
AddHandler AppDomain.CurrentDomain.FirstChanceException, Sub(sender, e)
Dim msg As New System.Text.StringBuilder()
msg.AppendLine(e.Exception.GetType().FullName)
msg.AppendLine(e.Exception.Message)
Dim st As New System.Diagnostics.StackTrace()
msg.AppendLine(st.ToString())
msg.AppendLine()
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim logFilePath As String = String.Format("{0}\{1}",desktopPath,"logfile.txt")
System.IO.File.AppendAllText(logFilePath, msg.ToString())
End Sub
You can launch a new instance of Visual Studio and attach it to the first Visual Studio instance to collect an exception’s call stack.
devenv.exe as a process to debug, and click the Attach button.See Also