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

Doing it all at once suggests factoring out all checks into a separate function, in which case it also makes sense to throw from that function, in order to give good exception messages depending on the specific error, and possibly including associated data in the exception. Which means that at the call site you won’t have any indented block structure differentiating the validation call from the rest of the function.

When programming with exceptions, it is the common case that a function consists of a sequence of steps each of which can fail and thus abort the function via an exception. Simple validation steps are not a special case in that respect.



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

Search: