Friday, May 18, 2012

GetErrorInfo Function VB.NET

Simple & useful Error Reporting Function... Thought I'd share if with you guys :-)

Module mFunctions
    Public Function GetErrorInfo(ByVal ex As Exception) As String
        Dim sb As New System.Text.StringBuilder()
        Dim st As New System.Diagnostics.StackTrace(ex, True)
        Dim FileName As String = ""
        Dim Method As String = ""
        Dim LineNumber As String = ""

        sb.AppendLine("")
        For Each frame As System.Diagnostics.StackFrame In st.GetFrames()
            FileName = frame.GetFileName
            Method = frame.GetMethod().ToString
            LineNumber = frame.GetFileLineNumber
            If FileName <> "" Then sb.AppendLine("Filename : " + FileName)
            If Method <> "" Then sb.AppendLine("Method : " + Method)
            If LineNumber <> "" Then sb.AppendLine("LineN° : " + LineNumber)
        Next
        Return sb.ToString()
    End Function
End Module

No comments:

Post a Comment