Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion over AggregateException Handle method

ReSharper was giving me a CoVariantConversion warning so I decided to google this and see how to fix it. I came accross this snippet of code:

 // ReSharper disable CoVariantArrayConversion
 try
 {
    Task.WaitAll(taskList.ToArray());
 }
 catch (AggregateException ex)
 {
    ex.Handle(e => true);
 }
 // ReSharper restore CoVariantArrayConversion

This part is confusing me:

 ex.Handle(e => true);

What does it do? I would think that it does nothing.

like image 985
cahoskins Avatar asked Aug 26 '13 19:08

cahoskins


2 Answers

You are correct: the line can be removed and have the same effect (causing all the exceptions to be considered "handled") as if the line was there.

The only time it would be useful is if the lambda could return false for some exceptions (which it doesn't in this case).

like image 89
Matt Smith Avatar answered Sep 18 '22 15:09

Matt Smith


This say, that the Exception is handled, nothing else.

like image 33
BendEg Avatar answered Sep 22 '22 15:09

BendEg