top | item 43018608

(no title)

billllll | 1 year ago

Is Rust praised for its checked errors? I've personally found it extremely verbose since there essentially is no possibility for unchecked errors.

Also, external crates like "anyhow" are required if you don't want to account for literally every single possible error case. Really seems like a pedantic's dream but a burden to everyone else.

Effective Java recommends checked exceptions only in the case where the caller may recover, but in practice you're usually just propagating the error to the caller in some form, so almost everything just becomes unchecked runtime exceptions.

discuss

order

vips7L|1 year ago

I'm only saying what I've seen here. I typically see praise for Rust's checked errors. Especially since they provide ? to panic and uncheck them. Personally I disagree with Bloch, if you are the thrower you can't possibly know if the caller can or cannot recover from your error so in my opinion its best to check it. If you are not the thrower and you can't recover from it I prefer to uncheck them, because if I can't recover my caller most likely can't either.

The issue really just arises with Java not giving you the capability to uncheck that error easily if you can't recover from it. For example, you need a ton of lines to uncheck:

    A doIt() throws B {
       throw new B();
    }

    void usingIt() {
       A a;
       try {
           a = doIt();
       } catch (B b) {
           throw new RuntimeException(b);
       }
       
       a.woohoo();
    }

My ideal situation would be for some sort of throws unchecked operator (or whatever syntax we want to bikeshed over) that turns them into unchecked exceptions.

    void usingIt() throws unchecked B {
        var a = doIt();
        a.woohoo();
    }

ninetyninenine|1 year ago

Have you heard of the language elm? The language elm is so safe that it is literally impossible to crash the program short of a memory error.

That's essentially the direction of modern programming languages. It's part of that feeling you get when programming haskell. Once you get it running, it just works. It's very different from the old paradigm where once you get it working, it can crash and you have to debug and do more to get it working better.