Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Java is the only mainstream language with checked exceptions and checked exceptions are nowhere near usefulness of static typing.

Following your logic, Java developers can now say “if you don’t like freedom of Java, use Rust/Haskell/Scala to validate everything at compile time”



Checked exceptions are part and parcel of a type system, though. If you have a foo function that returns a value or error you've got different options. Pseudo code they are:

foo():boolean throws Some, List, Of, Errors

foo():boolean | Some | List | Of | Errors

foo():(boolean | nil) , (nil | Some | List | Of | Errors)

The first is checked exceptions. The second is returning different types. Typically there's some sort of Option wrapper for ergonomics. The third returns a result, err tuple and by checking if err is nil you can see if foo succeeded.

Ultimately they are all the same. What differs is the boilerplate/syntax to accomplish what you want. If what you want is a generic error to handle unknown events then you gotta write it that way no matter which system you use.


You could say Rust error handling is more like checked than unchecked exceptions.


It is, that’s the whole point.


Java is not the only language that has checked exceptions. C++ has them too, for example, but thanks god virtually nobody uses them in C++.


Checked exceptions (i.e. "dynamic exception specification") were deprecated in C++11 and removed in C++17.


C++ never had checked exceptions. It had dynamic exception specifications but they were a very different (and useless) thing as they were runtime checked not statically.

I wish C++ had checked exceptions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: