Imports System.IO
Public Class Form1
Private Sub GerarLogErro(ByRef e As Exception)
Try
Dim sw As New StreamWriter("C:\Teste\LogErro.txt", True)
With sw
.WriteLine("Data: " & DateTime.Now.ToShortDateString())
.WriteLine("Hora: " & DateTime.Now.ToShortTimeString())
.WriteLine("Descrição do erro: " & e.Message)
.WriteLine("Computador: " & My.Computer.Name)
.WriteLine("Usuário: " & My.User.Name)
.Flush()
.Dispose()
End With
Catch
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim valor1 As Integer = 5
Dim valor2 As Integer = 0
Try
Dim ret As Integer = valor1 / valor2
Catch ex As Exception
Me.GerarLogErro(ex)
MsgBox("Ocorreu um erro inesperado.", MsgBoxStyle.Critical, "ERRO")
End Try
End Sub
End Class
0 comentários:
Postar um comentário