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

Using exceptions as control flow is a pattern I saw a lot at AWS in Java code.

It boiled down to it was simpler to abuse exceptions. You could instead return objects, but the code simply ended up being more to write.

At some point I tried to write things the 'proper' way by returning a Result object with the possible states, but it ended up being more complex than just throwing exceptions.



It’s because Java supports nonlocal returns and pattern matching, but only when you use exceptions. Returning POJOs to report problems makes all the intervening code harder to read because the happy path is no longer separated.




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

Search: