KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What would you prefer to see? try { var item = list.Single(x => x.HasFoo); } catch(InvalidOperationException e) { throw new InvalidOperationException("Exactly one item with foo expected, none found", e); } Or: var item = list.SingleOrDefault(x => x.HasFoo); if (item == null) throw new InvalidOperationException("Exactly one item with foo expected, none found"); What's the best practice here? Which one makes the exception more comprehensible?
Tags (comma-separated)
Save Edits
Cancel