Handling Unstructured Exceptions in VB.NET 2005/2008

I have several VB.NET support programs that have been ported from VB6 and use the old style of Unstructured Exception Handling:

On Error GoTo yyy

My question is, can I get a stack trace when using unstructured exception handling or do I need to convert all of them to structured exception (Try / Catch) handling to catch the exception with its full stack trace.

+3
source share
2 answers

, , , . .

GetException Err - StackTrace. :

Public Class Form1

Public Sub New()

    ' This call is required by the Windows Form Designer.' 
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.' 
    On Error GoTo ErrHandle

    Call test()        
    Exit Sub 

ErrHandle:
    MsgBox("Stack trace " & Err.GetException.StackTrace)
    Exit Sub

End Sub 


Private Sub test()
    Call test2()
End Sub

Private Sub test2()
    Dim d(2) As Double

    MsgBox(d(-1))
End Sub
End Class
+4

, . , , , StackTrace.

NB. -hhem - "" .

MethodName = (New StackFrame(0)).GetMethod.Name ' Get the current method
MethodName = (New StackFrame(1)).GetMethod.Name ' Get the Previous method
MethodName = (New StackFrame(2)).GetMethod.Name ' Get the method before that
+2

Source: https://habr.com/ru/post/1710229/


All Articles