Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

DisplayExceptionInfo - Displaying error information

Total Hit ( 2791)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
' A reusable routine that displays error information
' Note: requires Imports System.Reflection

Sub DisplayExceptionInfo(ByVal e As Exception)
  ' Display the error message.
  Console.WriteLine(e.Message)

  Dim st As New StackTrace(e, True)
  Dim i As Integer

  For i = 0 To st.FrameCount - 1
    ' Get the i-th stack frame.
    Dim sf As StackFrame = st.GetFrame(i)
    ' Get the corresponding method for that stack frame.
    Dim mi As MemberInfo = sf.GetMethod
    ' Get the namespace where that method is defined.
    Dim res As String = mi.DeclaringType.Namespace & "."
    ' Append the type name.
    res &= mi.DeclaringType.Name & "."
    ' Append the name of the method.
    res &= mi.Name
    Dim objParameters() As ParameterInfo = sf.GetMethod.GetParameters()
    Dim objParameter As ParameterInfo
    Dim strParameterString As String = ""
    strParameterString &= "("
    For Each objParameter In objParameters
      'Only add commas if there are more than one parameter
      ' (default length of 0 plus the opening parenthesis = 1).
      If strParameterString.Length <> 1 Then
        strParameterString &= ", "
      End If
      strParameterString &= objParameter.Name & " As " & _
        objParameter.ParameterType.Name
    Next
    strParameterString &= ")"
    res &= strParameterString

    ' Append information about the position in source file
    ' (but only if Debug information is available).
    If sf.GetFileName <> "" Then
      res &= " (" & sf.GetFileName & ", Line " & sf.GetFileLineNumber & _
        ", Col " & sf.GetFileColumnNumber
    End If
    ' Append information about offset in MSIL code, if available.
    If sf.GetILOffset <> StackFrame.OFFSET_UNKNOWN Then
      res &= ", IL offset " & sf.GetILOffset.ToString
    End If
    ' Append information about offset in native code.
    res &= ", native offset " & sf.GetNativeOffset & ")"

    Console.WriteLine(res)
  Next
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.