|
|
|
|
|
by Ferret7446
503 days ago
|
|
Stack traces are expensive. You need to make a conscious decision whether you want a stack trace attached to a particular error (and possibly where it gets attached, if you want it higher in the call chain), which aligns with Go's design philosophy for error handling. |
|
But go's do not have to be. A compiler can expand "foo()?" to something like:
err := foo(); if err != nil { return err.WithStringContext("foo() in MyFile.go:25"); }
The only complexity there is appending a constant pointer to "err", and this only happens in error case that uses "?". Depending on implementation it could be a single word write, if compiler can prove there are no other users of "err".
(And if your code is carefully written to be allocation-free and appending a pointer kills that? In this case, you don't have to use "?", put "return err" directly.)