'Returns a string representing a full stack for a passed in exception and all inner exceptions
'will only get the first 50 inner exceptions to prevent stack overflow
Private Function fullStackTrace(ByVal ex As Exception) As String
If ex Is Nothing Then
Throw New ArgumentException("ex can not be null", "ex")
End If
Dim outputStack As New System.Text.StringBuilder
outputStack.Append(ex.StackTrace)
Dim innerReferences As Byte = 0 'used to ensure memory does not run out
'during stack looping
Dim innerException As Exception = ex.InnerException
While Not innerException Is Nothing _
AndAlso innerReferences < 50
outputStack.Insert(0, innerException.StackTrace)
innerException = innerException.InnerException
innerReferences += CByte(1)
End While
Return outputStack.ToString
End Function
|