Created
May 12, 2015 18:12
-
-
Save michaeljbailey/28e84d2e1e7cc1217d2f to your computer and use it in GitHub Desktop.
Unwraps exceptions to the specified exception type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ExceptionExtensions | |
{ | |
public static TException Unwrap<TException>(this Exception exception) where TException : Exception | |
{ | |
for (; exception != null; exception = exception.InnerException) | |
{ | |
var typedException = exception as TException; | |
if (typedException != null) | |
{ | |
return typedException; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment