Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Last active December 11, 2015 23:48
Show Gist options
  • Select an option

  • Save JakeGinnivan/4679496 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/4679496 to your computer and use it in GitHub Desktop.
Linqpad script
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