In Java, checked exceptions allow developers to define in advance which exceptions a function can throw. However, it seems that Go does not have such a feature. Would it be considered a best practice in Go to document the possible errors that an API function can return? Additionally, what are some best practices that API providers can follow to help API users handle errors effectively?
On Feb 3, 2025, at 6:01 AM, Byungjun You <schi...@gmail.com> wrote:In Java, checked exceptions allow developers to define in advance which exceptions a function can throw. However, it seems that Go does not have such a feature. Would it be considered a best practice in Go to document the possible errors that an API function can return? Additionally, what are some best practices that API providers can follow to help API users handle errors effectively?
On Feb 4, 2025, at 4:59 PM, Darren Grant <darren....@gmail.com> wrote:What's the current best practice for getting a stack trace from an error passed up from further down in the stack?E.g. a web server middleware uses recover to catch panics. In the recover, we want the stack trace of the code that created the first error in the stack.
P.S. I threw this together to answer the question, but if anyone else notices something I missed or did wrong, it would be great if you could mention it as I would actually like to use this code moving forward.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/153B81DA-6CD3-4139-A7DE-C482CFF838DD%40newclarity.net.
On Feb 5, 2025, at 3:44 PM, Uzondu Enudeme <will...@gmail.com> wrote:
On the naming I also thought TraceError could be called StackError so that NewStackError would return *StackError.Maybe we can just rename it to be NewTraceError() since it returns *TraceError.
One observation is that the implementation of NewStackError also accepted a variadic parameter for wrapped errors but only used the first one. A small update could be to use errors.Join(wrapped...) to capture all passed in errors.This is useful when using expressions like `errors.Is`, only the first error is found in the tree even when multiple errors are passed in. Any exposed API is most likely to be depended upon even when the designer didn't plan for it to be used.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/f3871600-0bd2-4a91-b94b-f24fa7828a40n%40googlegroups.com.