April 2018
Intermediate to advanced
300 pages
7h 41m
English
The asynchronous method should always throw exceptions that are assigned to the returning task. However, the usage errors, such as passing null parameters to the asynchronous method, should be properly handled.
Let's suppose we want to generate several documents dynamically based on a predefined templates list, where each template populates the placeholders with dynamic values and writes it on the filesystem. We assume that this operation will take a sufficient amount of time to generate a document for each template. Here is a code snippet showing how the exceptions can be handled:
static void Main(string[] args)
{
List<Template> templates = GetTemplates();
IEnumerable<Task> asyncDocs = from template in templates select GenerateDocumentAsync(template); ...