The problem is that the exception will be invisible until you decide to wait. Thus, the action of the await call means that you will eventually observe the exception at some point when the final value is returned, or if you wait for the task to complete. However, if you don't care (it's a fire task and forget it), then exception is not a problem (for the most part).
I also find this a bit strange, you always need to try / catch the task to handle generalized exceptions. However, think about this a bit:
try { var myResult = await Foo(); // Do Success Actions Here... } catch(AggregateException e) { e.Flatten().Handle(ex => { if(ex is OperationCanceledException) { // Do Canceled Thing Here return true; } return false; }); }
It is not too far. In many ways I think about canceling another task and how can I do this? ThreadAbortException ? It seems until has been done to just throw a specific exception on cancellation.
This is pretty much a pattern that I've seen in several places, in order to handle cancellation.
source share