|
|
|
|
|
by TheDong
1542 days ago
|
|
I addressed that with the start of my comment: "Let's look at a common example: you want to return two different types of errors and have the caller distinguish between them" Yes, your example implements the error interface, but it's not realistic. There is real go code that does that, but that's the reason I have to do string-matching type error handling in go, and frankly it's an argument against the language that its error handling is such a mess that some people see that as reasonable. Having code that does return errorString("You have to do string matching on me internal error")
is something you can do, sure, but it's not good code. Idiomatically in go, it would also be "errors.New", not this errorString type you made.In rust, that would also be just as easy since it would be: bail!("oh no internal error")
using anyhow, which is the de-facto standard way to do crappy string-style erroring, like the above.But that's not what I want to talk about since that sort of error handling isn't interesting in either language, and isn't where they differ. |
|
You didnt do so, because implementing an error interface in Rust is a painful and extremely verbose process. Its not in Go, as I demonstrated.
> bail!("oh no internal error")
another Rust package. Are you unable to just write Rust without importing something?