I am thrown into an existing codebase, and part of the job is to gradually test the code when I make updates. Thus, it is the process of accepting something old and ugly and makes it more enjoyable.
In this case, there is code similar to this:
foreach (var thingamajigLocator in thingamajigLocators) { Thingamajig thingamajig; try { thingamajig = thingamajigservice.GetThingamajig(thingamajigLocator); } catch {
This is ugly and theoretically, if the exception is handled further down, you do not need to handle it here, but like the code at present, it works too much to process the service code.
I would like to do something like this:
thingamajigCollection = thingamajigLocators .Select(tl => thingamajigservice.GetThingamajig(tl)) .Where( );
Is this possible anyway? Any other suggestions? I can of course leave foreach with try / catch, but it seems like it might be more elegant since I don't care what the actual exception is in this case. Which again, I know, this is a terrible form, and it will need to be solved, but now it does not have time.
source share