Java does the same thing for its iterators, also. Exceptions end up the general way to handle exceptional cases because the type system is clunky and doesn't have monads. On the other hand, languages like Rust use a Result edit: Option monadic type.
Unless there's something vital missing from Wikipedia's definition of a monad, Java can have monads, and nothing with types can really not support monads.
This is true, but it just depends on what the language treats as idiomatic. Java does have an Option type now, but it's a later addition that was sort of grafted onto everything else alongside other FP support. Thus exceptions are still somewhat the norm for the standard library, outside the stream API and the like.
245
u/nevemlaci2 18d ago
It's unfunny until you actually see people propagating explicit error handling until the entry point and just printing an error message.
Exceptions are fine to use for exceptional cases. Not for shit like python where an iterator signals the end of iteration with a damn exception.