178
var childTask2 = Task.Factory.StartNew(() => throw new Exception("Exception from child2 task"), TaskCreationOptions.AttachedToParent);
1
using System;
2
using System.Threading.Tasks;
3
using System.IO;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
//HandlingExceptionFromSingleTask();
10
//UsingExceptionProperty();
11
//HandlingExceptionFromMultipleTasks();
12
//HandlingExceptionFromAttachedNestedTask();
13
//FlatteningExceptionFromAttachedNestedTask();
14
//HandlingExceptionFromDetachedNestedTask();
15
UsingAggregateExceptionHandle();
16
}
17
18
private static void HandlingExceptionFromSingleTask()
19
{
20
var task = Task.Run(() => throw new Exception("An exception occured"));
21
try
22
{
23
task.Wait();
24
}
Cached Result
directory not found exception handled
Tasks Exception: ArgumentNullException Value cannot be null. (Parameter 'path')
Tasks Exception: ArgumentNullException Value cannot be null. (Parameter 'path')