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

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

    You can use the StackTrace to retrieve the line number on an error.

    Try 
        'Put your code here
    
    Catch ex As Exception
        Dim trace = New Diagnostics.StackTrace(ex, True)
        Dim line As String = Right(trace.ToString, 5)
        MessageBox.Show("'" & ex.Message & "'" & " Error in- Line number: " & line)
    
    End Try
    

提交回复
热议问题