The Daily WTF
A common pattern is “global error handlers”- functions you call in your catch block that do some task, usually logging, when an exception occurs. Given that exception handling frequently involves a fair bit of repeated code, centralizing that isn’t a terrible idea. So when Magnus found code like this in the codebase, he didn’t think much of it:
public List<ErrandComboClass> GetErrandCombo() { List<ErrandComboClass> list = null; try { using (MyEntities my = new MyEntities()) { list = my.Errand.Select(x => new ErrandComboClass { ID = (int)x.Id, Name = x.Dnr }).OrderBy(x => x.Name).ToList(); } } catch (Exception ex) { ExceptionHelper.CatchError(ex); } return list; }
I can’t say I love the naming conventions, but it’s a pretty straight forward C# Linq method, projecting and sorting data. I don’t think that the ToList should be there, because we could be leveraging lazy evaluation (or maybe we shouldn’t, I don’t know their access patterns,
To read the full article click on the 'post' link at the top.