Comment

Comment by adrusi

Rust doesn't have exceptions, but its error handling is less ugly than go. Functions that can encounter errors return a `Result` by convention. If you then want to propagate errors, you can do so nicely with the try! macro, which converts a successful `Result` into its value, or returns the error of an unsuccessful `Result`. Thus the following go and rust are semantically the same:

    val, err := error_prone()
    if err != nil {
        return nil, err
    }
    
    let val = try!(error_prone());
Personally, I find that error handling isn't that bad in go. I think it's at least no worse than exceptions. Exceptions make it too easy, for me at least, to just mindlessly propagate the error. Sometimes that's the right thing to do, but in go it's a lot less repulsive to handle the error since to propagate the error you would need handling code anyway.

Rust strikes a nice balance. You have to explicitly handle every error, but if you go with the by far most common handling code, you get some nice sugar that makes it mostly painless.

parent adrusi 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton