3 ms·
> Many errors in go are simply: > var ErrFoo = errors.New("error doing Foo") That's just a matter of having a built-in struct for generic errors no? Rust c
by masklinn 12y ago
> Many errors in go are simply:
> var ErrFoo = errors.New("error doing Foo")
That's just a matter of having a built-in struct for generic errors no? Rust could probably provide a trivial error type (implementing the relevant traits) for this case.
- NateDad 12y agoYeah,that's a good point. Certainly Rust or anyone else could implement a simple function that returns a populated error struct with the given string message. I guess my initial reaction of a lot of boilerplate was mainly due to the default Rust error having a message, description, and a cause, instead of Go's default error that just has the message. Adding a description and cause is easy enough, and if you defined them for every error in Go, it would probably look pretty similar. My apologies.
- burntsushi 12y ago> I guess my initial reaction of a lot of boilerplate was mainly due to the default Rust error having a message, description, and a cause, instead of Go's default error that just has the message. The `Error` trait in Rust only demands that you define the `description` method.[1] The other two are optional. [1] - http://doc.rust-lang.org/std/error/trait.Error.html http://doc.rust-lang.org/std/error/trait.Error.html