51 comments
xvector · 6 days ago
I was following the article and nodding my head all the way up to the Rust section, at which point I lost track because I'm not too familiar with Rust :)

It's also not clear to me how `if let , while let , let-else` help (and how you'd use them), or what an "ergonomic sum type" is and how it helps with exceptions.

Would be really cool if there was a code snippet in Rust comparing/explaining the advantage over Java for each benefit.

Show replies

LAC-Tech · 6 days ago
I actually miss exceptions sometimes in rust.

I know all about Result, it's great for errors that are recoverable. But there's a lot of errors that aren't really recoverable inside a library, but you may not want to cause the code using that library to crash - perhaps your buggy component can be worked around.

Ocaml has both algebraic data types and exceptions, and works really well.

Show replies

unsnap_biceps · 6 days ago
> Can you guess why I used an intermediate variable instead of calling f(g(x)) and f(gException) in try-catch?

I can't guess why. Could someone explain why the intermediate variable is important?

Show replies

protomolecule · 6 days ago
>f(g(x));

>Exceptions make this (and similar) patterns suffer so badly.

Why one would want to pass an error as an input to a function that expects valid data?

Show replies

brabel · 6 days ago
Will people keep writing these annoying posts with no insight just to complain about Exceptions (and Java in general)?

I've done a lot of Java. And quite a bit of Rust too. The least thing (or close to it) that annoys me with Java is Java's error handling. It only really makes me upset when a lambda needs to call some method that has a checked Exception in its signature, usually because it does IO... yeah that's annoying... but I still get the job done without losing more than 30 seconds. Otherwise, I just make a decision on whether to handle errors locally or propagate them, and that's all there's to it.

Rust is nice and all. But the kind of annoyance I get with Result values are probably worse than is the case in Java with Exceptions. For example, as mentioned in the article, when you end up having multiple incompatible errors and you have to manually hack something, usually losing context, to make the compiler happy. Almost every project just adds yet another dependency on one of the error handling libraries (because this problem and similar ones, like losing the stack trace entirely, are all too common so there's lots of libraries to fix that) and you probably will end up with all of them in your project once you've written anything non-trivial.

The problem with API changes in Java are real, but the same exact issue exists in Rust: you inevitably have to end up adding new error scenarios as you add features to a library. Instead of a new Exception, you just end up with a new Error variant in Result.

Anyway, even though in the beginning I also got all euphoric with Rust, thinking it fixed every issue with every language, today I think it just shifted the sorts of problems you have to deal with. It definitely went in the right direction (specially with handling of closable resources and concurrency) and it's a better language in almost every way than Java and most languages. But sorry, with regards to error handling, it's a minor improvement at best.

Show replies