Like Java's "throws" keyword?
Like Java's "throws" keyword?
For general results cases (i.e. non exceptional cases), there exist a million small solutions in java.
In that other subthread, several problems are mentioned that occur even when you use checked exceptions only for exceptional control flow. The big ones that come to my mind are that functional-style methods like .map() and .filter() and the corresponding interfaces like Function<> and Predicate<> cannot deal with checked exceptions at all; the other (related) is that declared exception types cannot use type variables.
With result types, error handling becomes non-exceptional control flow and you can use .filter() and .map() to handle the error cases themselves. With Java's unchecked exceptions, error stay exceptional and the functional-style methods pass them on transparently. Checked exceptions cannot do either, and are incompatible with functional-style methods.
yes, that's the problem ahha
It's unfortunate that Java's checked exceptions do not work in Java's functional APIs like Streams.
I personally find Rust's way of doing things superior (for reasons masklinn mentioned in his comment), but it's basically the same principle, just realised in a different way.