Get an exceptions full stack trace with inner ex
3
This function returns a stack trace for an exception with all inner exceptions include unless the count of inner exceptions goes over 50. A stack overflow can occur if there is no upper limit for inner exceptions to read from.
Makes use of stringbuilder to build return string in order to yield higher performance.
Makes use of stringbuilder to build return string in order to yield higher performance.
'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






It'd probably be better to throw an InvalidOperationException instead of just bailing at the limit of 50.
You should also use recursion over your loop.
I submit my suggestion for improvement (although it's in C#)