Windows Phone Developers

Friday, July 13, 2007

StackTrace in Visual Basic .Net

StackTrace in VB.Net

Stack Trace is a string that describes the contents of the call stack, with the most recent method call appearing first.

This is most commontly used to know the place of code that generated an exception

Sub Stack_Trace_Exception_Example()

Try
Dim iVar As Long
iVar = "Assign String"
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub

The above example shows the stacktrace in message box when the type mismatch exception is thrown

The execution stack keeps track of all the methods that are in execution at a given instant. A trace of the method calls is called a stack trace. The stack trace listing provides a means to follow the call sequence to the line number in the method where the exception occurs.

StackTrace may not report as many method calls as expected, due to code transformations, such as inlining, that occur during optimization.

The StackTrace property is overridden in classes that require control over the stack trace content or format. By default, the stack trace is captured immediately before an exception object is thrown. Use Environment.StackTrace to get stack trace information when no exception is being thrown as shown below:


Sub Stack_Trace_Environ_Example_Level1()
Console.WriteLine(System.Environment.StackTrace.ToString)
Stack_Trace_Environ_Example_Level2()
End Sub

Sub Stack_Trace_Environ_Example_Level2()
MsgBox(System.Environment.StackTrace)
End Sub

The trace output is shown below:

Stack Trace Picture

StackTrace in VB.Net, Exception Handling in VB.Net, Environment.StackTrace



Technorati Profile
Add to Technorati Favorites


Academics blogs
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005