[Solved] How to access and use the stack-trace to help identify a bug


When you get an error message as shown below click on the View Detail.. link.

Error Report

This will open this property box.

Expand the exception to show the details and hover the mouse over the StackTrace property.

Error Details

Most of what you see listed there will probably be Greek to you (Apologies to the Grecian friends reading this), but if you look closer you will see lines that say

at “NAME OF A MODULE”:Line 230 (or wherever)

The first line like that in the trace is the line that finally crashed the code. Simply go find that line in your code and try and figure out why that particular line is causing the specified error.

Subsequent lines of that format are the point in your code where the routine listed above was called from.

Now the images above are not a very good example since the IDE debugger stopped at the error line. But regardless, the stack-trace in invaluable when you properly trap errors in a try / catch statement. One of the properties of the exception is the stack-trace.. view it or dump it to the immediate window.

    Try

    Catch ex As Exception
        Debug.Print(ex.StackTrace)
    End Try

Also when running the exe version be familiar with the details pane. Its the same stack-trace.

enter image description here

solved How to access and use the stack-trace to help identify a bug