[HttpPost]
public async Task<JsonResult>
{
await sendNotification(responce);
}
I want to catch exception occured in sendnotification method. How can I call the same using Task.Factory ??
You just write a try/catch block, as such:
[HttpPost]
public async Task<JsonResult>
{
try
{
await sendNotification(responce);
}
catch (Exception ex)
{
...
}
}
You don't need Task.Factory for this.
Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) and any evidence of the real exception is lost as inner exception is null.Exception Handling of sendNotification() task depends on how the task is coded. In one way, above Stephen Cleary's answer is right but not sure it fixes your issue.
You can go through below easy understandable articles to understand Exception Handling in Async programming...
Basic exception handling in Asynchronious programming in C#.
Also look into below link..
Handling the AggregateException using Handle method in Asynchronous programming.
Taskand sent back in the result (checkTask.Result). Obviously you can try/catch inside the method and throw the appropriate exception