How to handle unhandled exceptions in Task awaiter

I am having problems with unhandled exceptions being thrown in the task awaiter. These exceptions are just ignored and never propagated anywhere.

Code example:

Task<bool> Execute()
{
    TaskCompletionSource<bool> tcsrc = new TaskCompletionSource<bool>();
    Task.Delay(50).ContinueWith((t) => {
        tcsrc.SetResult(true);
    });
    return tcsrc.Task;
}

async Task<bool> Test()
{
    bool result = await Execute();
    throw new Exception("test");
    return result;
}

In this example, Test() awaits on task returned by Execute() and then throws an exception. This exception is never handled anywhere and the only place I am able to catch it is Application's FirstChanceException handler. After this handler is executed, the exception gets just ignored.

The Test() itself is called via chain of async calls from some UI event handler. So I assume it should be propagated to that UI event handler and thrown there. But it never happens.

Is there something I miss?

Edit: According to FirstChanceException handler, the exception is reproduced three times before becoming ignored with the following stack trace:

at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
Jon Skeet
people
quotationmark

The Task<bool> returned from your Test method will become faulted. If you await that task (or call Wait() on it) then the exception will be rethrown at that point. If you choose to ignore the faulted state of the task, then yes, you'll be ignoring the exception.

people

See more on this question at Stackoverflow