December 2019
Intermediate to advanced
346 pages
9h 8m
English
The following is a sample async method that returns a Task. The method, in turn, calls another method, DoSomethingFaulty (), which throws an exception.
Here is our DoSomethingFaulty() method implementation:
private static Task DoSomethingFaulty() { Task.Delay(2000); throw new Exception("This is custom exception."); }
And here is the code for the AsyncReturningTaskExample() method:
private async static Task AsyncReturningTaskExample() { Task<string> task = DoSomethingFaulty(); Console.WriteLine("This should not execute"); try { task.ContinueWith((s) => { Console.WriteLine(s); }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); ...Read now
Unlock full access