How to use Stacktrace to return Error Line Number in vb.net

后端 未结 7 1087
名媛妹妹
名媛妹妹 2021-02-05 20:08

I am trying to create some sort of error catching method that will return the error line number. We have an abort email that is sent out when a process aborts that gives us the

7条回答
  •  不思量自难忘°
    2021-02-05 20:45

        Try
            Dim x As Integer
            x = " "
    
        Catch ex As Exception
            Dim trace = New Diagnostics.StackTrace(ex, True)
            Dim line As String = Strings.Right(trace.ToString, 5)
            Dim nombreMetodo As String = ""
            Dim Xcont As Integer = 0
    
            For Each sf As StackFrame In trace.GetFrames
                Xcont = Xcont + 1
                nombreMetodo = nombreMetodo & Xcont & "- " & sf.GetMethod().ReflectedType.ToString & " " & sf.GetMethod().Name & vbCrLf
            Next
    
            MessageBox.Show("Error en Linea number: " & line & ex.Message & vbCrLf & "Metodos : " & vbCrLf & nombreMetodo)
    
        End Try
    

提交回复
热议问题