IMNERHO, the one significant misstep in checked exception based error handling is that languages don't (AFAIK!) require call sites to be marked. If a function is marked as throwing an exception, and it's called from another function marked as throwing the same exception, that's enough. There's no indication to the reader that an exception can be thrown at a particular point, much less the the author was aware of the fact that it can!
Go's if (err != nil) { return err; } and Rust's ? both do that.
You could imagine a variant of Java where you had to write this:
Byte readOptionalByte(InputStream in) throws IOException {
int flag = try(in.read());
if (flag == 0) return null;
else return (byte) try(in.read());
}
Which might be better.
Unchecked exception based error handling, of course, is irretrievably broken.
Go's if (err != nil) { return err; } and Rust's ? both do that.
You could imagine a variant of Java where you had to write this:
Which might be better.Unchecked exception based error handling, of course, is irretrievably broken.