Last active
December 11, 2015 23:48
-
-
Save JakeGinnivan/4679496 to your computer and use it in GitHub Desktop.
Linqpad script
This file contains hidden or 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
| void Main() | |
| { | |
| DoShiz(); | |
| } | |
| public async void DoShiz() | |
| { | |
| var worker = new Worker(); | |
| var ex = await ThrowsExceptionAsync<ArgumentException>(async () => await worker.GetMessage(" ")); | |
| var ex2 = await ThrowsExceptionAsync<ArgumentException>(() => worker.GetMessage(" ")); | |
| ex.Dump(); | |
| ex2.Dump(); | |
| } | |
| public class Worker | |
| { | |
| public async Task GetMessage(string message) | |
| { | |
| throw new ArgumentException(); | |
| } | |
| } | |
| public static async Task<TException> ThrowsExceptionAsync<TException>(Func<Task> func) | |
| where TException : Exception | |
| { | |
| try | |
| { | |
| await func().ConfigureAwait(false); | |
| } catch (TException e) | |
| { | |
| return e; | |
| } | |
| throw new Exception("Delegate did not throw " + typeof(TException).Name); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment