4 ms·
Go errors are a specific type and that type is extensible. You can attach additional data to an error, and in recent versions of go you can wrap errors in other
by timdorr 6y ago
Go errors are a specific type and that type is extensible. You can attach additional data to an error, and in recent versions of go you can wrap errors in other errors. You can do instance checking against an errors.New error, or do a type check against the kind of error you get back. This ultimately gives you significantly greater control and functionality over error codes.
- throw_m239339 6y agoGo errors are a convention. Nothing forces you to use error interface to do anything nor handle anything either. See my comment here: https://news.ycombinator.com/item?id=23759196 https://news.ycombinator.com/item?id=23759196 > You can attach additional data to an error, and in recent versions of go you can wrap errors in other errors. Yes, with a function added to the std lib after people used a 3rd party lib for years to do the same thing. Nothing to do with a change of language structure or features.
- bathtub365 6y agoYou could do much of that with C structs as well.