The author fails to convince me that there is some principle involved. In the last paragraph, he even mentions how to deal with checked exceptions, which brings me to this:
The Trouble with Checked Exceptions
There are a few points here, but the main is, IMO, that people just don’t care to handle all of those exceptions. They either don’t care because they have some exception handler in place already (provided by a web framework, for example) or they just want to stay on the happy path and build that useful functionality. They will circumvent checked exceptions anyhow, and it is only trouble for them that they have to do that.
Whenever Go folks call if err != nil
exception handling, I’m in disbelief. Just a quick search on GitHub, they either do panic(err)
or return nil, err
or myLogger.Fatal(err)
. I’m sure there are examples of actual exception handling, but most aren’t. The three above are just exceptions with extra steps, code that could be added by the Go compiler. I just don’t see the benefits.
Now Rust might be different due to its goals (close to metal/exceptions don’t mix?), but a quick look at Rust book and the first example of exception handling is this.
fn main() {
let greeting_file_result = File::open("hello.txt");
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {error:?}"),
};
}
To be fair, this is what I would do in Haskell if open
returned Either
.
That being said, I really like checked exceptions, if I want to force myself to do something consistently. Forcing others just doesn’t work that well.