When an exception is thrown from the async method, it is captured in the task, so it does not throw until the task is detected by calling Task.Wait() , Task.Result , waiting for the task or accessing the Exceptions property of the task.
In terms of input arguments, one way around this is to split the method into two parts, first check the input arguments, and then call the second method, which is equal to async . See this answer to Stephen Cleary's question for an example. Thus, the exception of the input argument will be thrown immediately outside the task returned by the method.
Ned stoyanov
source share