Re:Error stack traces in Go with x/xerror
by zarzavat on Tuesday August 24, 2021 @04:21AM
(#28286278)
If you make it an environmental error then the programmer is likely to write an error handler that ignores the error because it can "never" happen and the compiler is forcing them handle it. You now need a linter to prevent this and a way to signal to the linter that "no I really intended to ignore that error, I promise"
Whereas exceptions fail safe, ignoring the error means not catching it, which means if the error does occur, it will load up the debugger.
This is the whole Java "checked exceptions" misfeature again.
Exceptions do exist in Go, it’s called “Panic”. This whole “Go doesn’t have exceptions” meme is completely untrue. It’s just not the preferred way of error handling because, unsurprisingly, most application errors are going to be environmental. But if you select an out of bounds index in a slice or don’t handle a nil pointer correctly you’d get a panic — because those are clearly developer issues that warrant a stack trace rather than environmental problems that need a friendly user facing error message.