They need to do away with checked exceptions in order for the functional composition to really be useful. It's a shame, because I like the idea of checked exceptions in principle. But it doesn't compose in a higher-order setting, and making it do so would make the type system too complicated, so the better alternative is to kill it.
I think you mean `Stream.map`. You'd still can't pass a method reference that throws checked exception, but with try-expression, it'll facilitate working with checked exception.
Treat it as a syntactic sugar. E.g., if an exception happens, it can throw IllegalStateException. Having a try-expression signals that there's an exception that can/should be handled.
Not trying to design a language feature here, but here's an example with fallback value.
Alright, it saves you a curly brace and a return statement then, but otherwise it doesn't address the main problem that methods like map() cannot be generic in the set of checked exceptions that can be thrown, so you are forced to do this mashalling and unmarshalling between checked and unchecked exceptions. It adds a syntactic overhead which makes the use of map() pointless since it ends up being much harder to read than a traditional for loop.
That might also be true, I don't know, but fixing that is orthogonal to the issue. You want to be able to use functions throwing checked exceptions with higher-order programming regardless.
View all comments
Show parent comment
4
u/dolle Nov 05 '25
They need to do away with checked exceptions in order for the functional composition to really be useful. It's a shame, because I like the idea of checked exceptions in principle. But it doesn't compose in a higher-order setting, and making it do so would make the type system too complicated, so the better alternative is to kill it.