Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: