Catch JIT Errors in Visual Studio

Asked by At

I am trying to write any errors out our users receive in a application to a log file and I was wondering if there is any way to catch JIT errors and if so what is the code to do this?


1 Answers

user238615 On

Based on what nbk is saying, you could do something like this

Private Sub LogEx()
        'Some stuff that will fail
    Catch ex As Exception
        LogException(Environment.UserName, ex.ToString)
    End Try
End Sub

Private Sub LogException(ByVal Username As String, Ex As String)
    Dim LogFilePath As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\MyLog.txt"

    Dim MyLogFile As IO.StreamWriter =
        My.Computer.FileSystem.OpenTextFileWriter(LogFilePath , True)
    MyLogFile.WriteLine(Username & "---" & Ex)
End Sub