I have a custom exception InsertLeadException which inherts from Exception. Now, I have the code like:
....
try
{
isSuccess = _proxy.SendAsync(message).NoState();
}
catch (InsertLeadException ex)
{
...
}
catch (Exception ex)
{
...
}
....
Here is SendAsync in proxy:
public async Task<bool> SendAsync(Message message)
{
List<Task<bool>> tasks = new List<Task<bool>>();
var task = ProcessMessageAsync(message);
tasks.Add(task);
var legacyTask = LogLeadAsync();
tasks.Add(legacyTask);
Task.WaitAll(tasks.ToArray());
return task.Result; // only need return result of 1st task
}
In the ProcessMessageAsync, I simply does
throw new InsertLeadException("Test Exception.");
And in LogLeadAsync, there is no exception.
When run the code, for some reasons, it does not catch InsertLeadException, instead, it catches Exception.
But, if I implement like below, it does catch the InsertLeadException:
public async Task<bool> SendAsync(Message message)
{
var task = await ProcessMessageAsync(message).NoState();
var legacyTask = await LogLeadAsync().NoState();
return task;
}
Anyone knows why?
Thanks