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

后端 未结 7 1230
名媛妹妹
名媛妹妹 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:53

        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 = ""
    
            For Each sf As StackFrame In trace.GetFrames
                nombreMetodo = sf.GetMethod().Name & vbCrLf
            Next
    
            MessageBox.Show("Error en Linea number: " & line & vbCrLf & ex.Message & vbCrLf & "Metodos : " & nombreMetodo)
        End Try
    

提交回复
热议问题