, "" , , , . DoWorkAsync - , , "" :
DoWorkAsync().ContinueWith(t=>{
Console.WriteLine("Error occurred: " + t.Exception);
}, TaskContinuationOptions.OnlyOnFaulted);
, "" async, :
var task = DoWorkAsync();
task.Wait();
if(task.Exception != null)
{
Console.WriteLine("Error occurred: " + task.Exception);
}
, - :
var task = DoWorkAsync().ContinueWith(t=>{
if(t.Exception.InnerExceptions[0].GetType() == typeof(TimeoutException))
{
throw new BackoffException(t.Exception.InnerExceptions[0]);
}
}, TaskContinuationOptions.OnlyOnFaulted);
BackoffException :
if(task.IsFaulted)
{
Console.WriteLine(task.Exception.InnerExceptions[0]);
// TODO: check what type and do something other than WriteLine.
}