Get a meaningful exception message.

kanaida

Member
Joined
Oct 6, 2009
Messages
15
Programming Experience
3-5
Sometimes "Invalid Operation" or some random error just dosen't cut it because InnerException holds more details.

Try using this:

VB.NET:
 Public Function FullException(ByVal ex As Exception) As String
        Dim CurrentEx = ex
        Dim FullExceptionText As String = CurrentEx.Message

GetInnerText:
        If Not CurrentEx.InnerException Is Nothing Then
            CurrentEx = CurrentEx.InnerException
            FullExceptionText += vbCrLf & CurrentEx.Message
            GoTo GetInnerText
        End If

        FullExceptionText += vbCrLf & ex.StackTrace
        Return FullExceptionText
    End Function
 

Latest posts

Back
Top