emanuelx Posted April 13, 2012 at 05:24 PM Report #449045 Posted April 13, 2012 at 05:24 PM boas pessoal na minha aplicação tenho um código que ao detectar erros ele pergunta se quer enviar o relatório, mas só que aquilo tá bué fraquinho, porque por exemplo. ele manda-me assim o relatorio: OS:Microsoft Windows 7 Ultimate version:6.1.7601 Utilizador:EMANUEL-PC RAM: 4058616 MB System type:x64-based PC Processor:Intel(R) Core(TM) i3 CPU 530 @ 2.93GHz HD Size:1000201789440KB InvalidArgument=Value of '50' is not valid for 'index'. Parameter name: index era possível ter mais informações no relatório como o numero da linha ou a classe em que foi detectado o erro? código que eu tenho Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException 'Este evento é disparado quando ocorre um erro If MessageBox.Show("Send error report", "Error", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then Try My.Computer.Network.Ping("gmail.com", 500) Catch ex As Exception MsgBox("Não Tem Internet") Exit Sub End Try Try Dim infopc As String = "" Dim objOS As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") Dim objCS As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") Dim ObjP As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_Processor") Dim objHD As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") For Each ob In objOS.Get infopc += "OS:" + ob("Name").ToString().Split("|".ToCharArray())(0) + vbNewLine infopc += "version:" + ob("version").ToString() + vbNewLine infopc += "Utilizador:" + ob("csname").ToString() + vbNewLine infopc += "RAM: " + ob("TotalVisibleMemorySize").ToString() + " MB" + vbNewLine Exit For Next For Each ob In objCS.Get infopc += "System type:" + ob("systemtype").ToString + vbNewLine Exit For Next For Each ob In ObjP.Get infopc += "Processor:" + ob("Name").ToString() + vbNewLine Exit For Next For Each ob In objHD.Get infopc += "HD Size:" + ob("Size").ToString() + "KB" + vbNewLine Exit For Next Dim MyMailMessage As New MailMessage() MyMailMessage.From = New MailAddress("mail@gmail.com") MyMailMessage.To.Add("mail@gmail.com") MyMailMessage.Subject = ("versão os" & Environment.OSVersion.ToString & "versão" & Environment.Version.ToString) MyMailMessage.Body = infopc + vbNewLine + e.Exception.Message + vbNewLine Dim SMPT As New SmtpClient("smtp.gmail.com") SMPT.Port = 587 SMPT.EnableSsl = True SMPT.Credentials = New System.Net.NetworkCredential("mail@gmail.com", "pass") SMPT.Send(MyMailMessage) MsgBox("Sended, tanks to sended the report") Catch ex As Exception End Try End If e.ExitApplication = True End Sub com calma e sem stresses
José Lopes Posted April 13, 2012 at 10:14 PM Report #449077 Posted April 13, 2012 at 10:14 PM Podes ver alguns exemplos aqui: http://www.codeproject.com/Articles/7482/User-Friendly-Exception-Handling http://www.codeproject.com/Articles/2949/Managing-Unhandled-Exceptions-in-NET acho que devolvem mais informação que a tua. Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!
programadorvb6 Posted April 19, 2012 at 09:14 AM Report #449885 Posted April 19, 2012 at 09:14 AM Olá Emanuel. Veja se isto serve : Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim valor1 As Integer = 5 Dim valor2 As Integer = 0 Try Dim ret As Integer = valor1 / valor2 Catch ex As Exception Me.GerarLogErro(ex) MessageBox.Show("Ocorreu um erro inesperado.", "Informação : ") End Try End Sub Private Sub GerarLogErro(ByRef e As Exception) Try Dim sw As New IO.StreamWriter(Application.StartupPath & "\LogErro.txt", True) With sw Dim trace = New System.Diagnostics.StackTrace(e, True) .WriteLine("======================================| |======================================") .WriteLine("Data : " & DateTime.Now.ToShortDateString()) .WriteLine("Hora : " & DateTime.Now.ToShortTimeString()) .WriteLine("") .WriteLine("Computador : " & My.Computer.Name) .WriteLine("Utilizador : " & My.User.Name) .WriteLine("") .WriteLine("Descrição do erro : " & e.Message) .WriteLine("Formulário : " & trace.GetFrame(0).ToString) .WriteLine("Erro na linha : " & trace.GetFrame(0).GetFileLineNumber().ToString) .WriteLine("Na Coluna : " & trace.GetFrame(0).GetFileColumnNumber().ToString) .WriteLine("======================================| |======================================") .Flush() .Dispose() End With Catch End Try End Sub End Class Espero ter ajudado. Até+ Programadorvb6 ______________________________________________________________________________ Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé.
emanuelx Posted April 19, 2012 at 08:01 PM Author Report #450048 Posted April 19, 2012 at 08:01 PM já estou a usar a classe que estava lá no site com umas modificações com calma e sem stresses
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now