本文整理匯總了VB.NET中System.Diagnostics.StackFrame.StackFrame構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET StackFrame構造函數的具體用法?VB.NET StackFrame怎麽用?VB.NET StackFrame使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.Diagnostics.StackFrame
的用法示例。
在下文中一共展示了StackFrame構造函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
<STAThread()> _
Shared Sub Main()
Dim mainClass As New ClassLevel1
Try
mainClass.InternalMethod()
Catch
Console.WriteLine(" Main method exception handler")
' Display file and line information, if available.
Dim st As New StackTrace(New StackFrame(True))
Console.WriteLine(" Stack trace for current level: {0}", _
st.ToString())
Console.WriteLine(" File: {0}", _
st.GetFrame(0).GetFileName())
Console.WriteLine(" Line Number: {0}", _
st.GetFrame(0).GetFileLineNumber().ToString())
Console.WriteLine()
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
End Try
End Sub
示例2: InternalMethod
Public Sub InternalMethod()
Try
Dim nestedClass As New ClassLevel2
nestedClass.Level2Method()
Catch e As Exception
Console.WriteLine(" InternalMethod exception handler")
' Build a stack trace from one frame, skipping the
' current frame and using the next frame. By default,
' file and line information are not displayed.
Dim st As New StackTrace(New StackFrame(1))
Console.WriteLine(" Stack trace for next level frame: {0}", _
st.ToString())
Console.WriteLine(" Stack frame for next level: ")
Console.WriteLine(" {0}", st.GetFrame(0).ToString())
Console.WriteLine(" Line Number: {0}", _
st.GetFrame(0).GetFileLineNumber().ToString())
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub
示例3: StackTrace
Public Sub Level2Method()
Try
Dim nestedClass As New ClassLevel3
nestedClass.Level3Method()
Catch e As Exception
Console.WriteLine(" Level2Method exception handler")
' Display the full call stack at this level.
Dim st1 As New StackTrace(True)
Console.WriteLine(" Stack trace for this level: {0}", _
st1.ToString())
' Build a stack trace from one frame, skipping the current
' frame and using the next frame.
Dim st2 As New StackTrace(New StackFrame(1, True))
Console.WriteLine(" Stack trace built with next level frame: {0}", _
st2.ToString())
' Build a stack trace skipping the current frame, and
' including all the other frames.
Dim st3 As New StackTrace(1, True)
Console.WriteLine(" Stack trace built from the next level up: {0}", _
st3.ToString())
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub
示例4: StackTrace
Public Sub Level3Method()
Try
Dim nestedClass As New ClassLevel4()
nestedClass.Level4Method()
Catch e As Exception
Console.WriteLine(" Level3Method exception handler")
' Build a stack trace from a dummy stack frame.
' Explicitly specify the source file name and line number.
Dim st As New StackTrace(New StackFrame("source.cs", 60))
Console.WriteLine(" Stack trace with dummy stack frame: {0}", _
st.ToString())
Dim i As Integer
For i = 0 To st.FrameCount - 1
' Display the stack frame properties.
Dim sf As StackFrame = st.GetFrame(i)
Console.WriteLine(" File: {0}", sf.GetFileName())
Console.WriteLine(" Line Number: {0}", _
sf.GetFileLineNumber())
' The column number defaults to zero when not initialized.
Console.WriteLine(" Column Number: {0}", _
sf.GetFileColumnNumber())
If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN
Console.WriteLine(" Intermediate Language Offset: {0}", _
sf.GetILOffset())
End If
If sf.GetNativeOffset <> StackFrame.OFFSET_UNKNOWN
Console.WriteLine(" Native Offset: {0}", _
sf.GetNativeOffset())
End If
Next i
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub
示例5: StackTrace
Try
Dim [nestedClass] As New ClassLevel5()
[nestedClass].Level5Method()
Catch e As Exception
Console.WriteLine(" Level4Method exception handler")
' Build a stack trace from a dummy stack frame.
' Explicitly specify the source file name, line number
' and column number.
Dim st As New StackTrace(New StackFrame("source.cs", 79, 24))
Console.WriteLine(" Stack trace with dummy stack frame: {0}", _
st.ToString())
' Access the StackFrames explicitly to display the file
' name, line number and column number properties.
' StackTrace.ToString only includes the method name.
Dim i As Integer
For i = 0 To st.FrameCount - 1
Dim sf As StackFrame = st.GetFrame(i)
Console.WriteLine(" File: {0}", sf.GetFileName())
Console.WriteLine(" Line Number: {0}", _
sf.GetFileLineNumber())
Console.WriteLine(" Column Number: {0}", _
sf.GetFileColumnNumber())
Next i
Console.WriteLine()
Console.WriteLine(" ... throwing exception to next level ...")
Console.WriteLine("-------------------------------------------------")
Console.WriteLine()
Throw e
End Try
End Sub