ExtensionMethod.NET Home of 846 C#, Visual Basic, F# and Javascript extension methods


Returns the first inner exception you are looking for or null if not found.


<System.Runtime.CompilerServices.Extension()> _
Public Function TraverseFor(Of T As Class)(ByVal ex As Exception) As T

    If ex Is Nothing Then _
        Return Nothing

    If ex.GetType Is GetType(T) Then _
        Return TryCast(ex, T)

    Return TryCast(ex.InnerException.TraverseFor(Of T)(), T)

End Function


If Server.GetLastError().TraverseFor(Of SessionNAException)() IsNot Nothing Then _

Author: Brian Wigfield

Submitted on: 19 nov 2010

Language: VB

Type: System.Exception

Views: 3102