Created
October 21, 2012 02:47
-
-
Save nakamura-to/3925528 to your computer and use it in GitHub Desktop.
Rethrow the inner exception of a TargetInvocationException with .NET 4.5 ExceptionDispatchInfo
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var method = typeof (Program).GetMethod("Hello"); | |
try | |
{ | |
method.Invoke(null, new object[] {}); | |
} catch(TargetInvocationException e) | |
{ | |
var info = ExceptionDispatchInfo.Capture(e.InnerException); | |
info.Throw(); | |
} | |
} | |
public static void Hello() | |
{ | |
throw new Exception(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment