Why `throw/catch` is discouraged for control flow in favor of `with` special form?

Most of the exception workflows in the programming languages I worked with are frowned upon because they pass the responsibility for error handling in their own code to upstream callers. Which would be fine – if it was more visible.

(Java has checked exceptions that can be appended to the function signatures e.g. public void do_stuff_with_file(String path) throws IOException which helps but I’ve noticed many former colleagues have been outright ignoring those.)

So #1 reason for me is: code must be obvious through and through, 100%, including any and all errors it can return.

Code must not have surprising effects. Code should be “what you see is what you get”.

6 Likes