Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

vb.net - How to access and use the stack-trace to help identify a bug

I see a lot of posts from people saying they get error such and such but seem to have no idea how to figure out where the error is coming from.

As such I wondered if people know how to access and use the stack trace.

So how do you access it, and what does it mean and do for you?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...