4 ms·
The best parts of rust's error handling are the try!() macro (aka `?`), as well as From/Into error types allow the compiler to wrap types or convert between err
by andrewjf 7y ago
The best parts of rust's error handling are the try!() macro (aka `?`), as well as From/Into error types allow the compiler to wrap types or convert between error types. This eliminates almost all of the go boilerplate `if err != nil` and you only handle the error where you actually need to with pattern matching and destructuring, instead. It is much nicer. Go's error handling is pretty primitive, in my opinion.
- deleted 7y ago[deleted]
- aksx 7y ago>The best parts of rust's error handling are the try!() macro (aka `?`), Go's way of providing try!() macro is less magical but almost as useful.[1] > From/Into error types allow the compiler to wrap types or convert between error types error is an interface in Go which can be easily cast/checked for the underlying type. > Go's error handling is pretty primitive I wouldn't call it primitive, I would call it simple. I like the comparison i read on a blog on HN. Rust is the 'new' C++ and Go is the new C [1] https://blog.golang.org/errors-are-values https://blog.golang.org/errors-are-values
- xfer 7y ago> error is an interface in Go which can be easily cast/checked for the underlying type. Yeah it's done during runtime and the compiler won't be able to help you with it if you fail to do exhaustive type checking. It's a problem anytime you refactor your code. ADTs and pattern matching is pretty much the bare minimum language feature i expect from any statically typed language.