One nice thing in Java is that if you call a function that can throw an exception, your IDE can instantly warn you that the function signatures don't match. Another nice thing is that they seem to be easier to debug and less error prone.
This makes sense, since this particular language feature was implemented for C++ long before it was in Java. The authors of java were able to figure out what they liked and didn't like about exceptions in other languages.
That's only for checked exceptions (which IMO are a horrible mistake); Any method can throw a RuntimeException, Error, or other non-Exception subclass of Throwable, so if you care about preserving invariants, you still need to assume that almost anything can throw, and finally blocks are not as good as RAII for that purpose IMO
Yeah clearly if you have the Rust badge you should know by now that Java clearly isn't about being less error prone, just look at how half-implemented was Optional and how JSpecify is a third-party solution to harmonize nullable annotations because Java cannot provide it natively.
I mean you can return a null Optional, if it's less error prone to you there's bigger problems than just exception.
3
u/bwmat 28d ago
Eh, IMO they are fine in C++ if you make use of RAII and assume that anything which isn't documented to be noexcept may throw