DisplayExceptionInfo – Displaying error information

' A reusable routine that displays error information' Note: requires Imports System.ReflectionSub 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)    NextEnd Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS