3 ms·
I disagree with 4. How else would you recommend structuring this: try{ lst.Where(i => i.ID == itm.ID).First().Amount += itm.Amount } catch (InvalidOper
by jimmaswell 13y ago
I disagree with 4. How else would you recommend structuring this:
try{
lst.Where(i => i.ID == itm.ID).First().Amount += itm.Amount
} catch (InvalidOperationException) {
lst.Add(itm);
}
I could check if the list contains it first, but this is more convenient. This is just one small example of a lot of cases where I've used typed exceptions successfully - in some cases I have multiple catches that do different things, eg catch(InvalidOperationException){...}catch(ArgumentNullException){...} this saves a lot of lines of pre-checking and has a clear control flow.