Few questions #4
-
Hello, i am using package for a while in several projects and I am refactoring old code to get rid of underscores. I have stumbled to few issues that are missing from documnetation. Simple way to overwrite errors?Or just annotate single try, so i would be able to recognize type of error in error hadler. And if possible check if annotation is present. StacktraceWriter doesnt print annotations. Is this intentional?I thought that purpose of StackTraceWriter is to setup and forget about printing errors everywhere. Example to use try.Is()I am not sure how to use it. Also more examples please. Thank you for library. It helps with writing much better code. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello, and thank you very much for your comments and questions. They are highly appreciated! Simple way to overwrite errors?The current If I understand your question right, you would like to know what was the specific If you wrap the error in any handler, you can use Go's Please see the following playground example about how to 'override' or wrap the current error. The StackTraceWriter should print annotations. If not, it's not intentionalWhere stack tracing is on, please see this altered playground. Please also notice that there are two different stack traces. The highest level of the call stack
The annotation is shorter in the
I'm still open to suggestions. For our use cases, this has been enough, and to be honest, it's easiest to implement, and it has been most helpful for debugging. Example to use try.Is()About the examples, please see the official err2 Go documentation. About the
Summary of I hope I could have been a help. If you have any other questions or comments, please let me know. Best regards, |
Beta Was this translation helpful? Give feedback.
Hello, and thank you very much for your comments and questions. They are highly appreciated!
Simple way to overwrite errors?
The current
err2
package follows the Go2 try-proposal, where you add as many deferred error handlers as your function needs.If I understand your question right, you would like to know what was the specific
try.To
which triggered the error. The preferred (and only) way is to use as many deferrederr2.Handle
orerr2.Returnf
. The order of the handlers tells what to do in the particular error handler. Please see the following playground. There is just oneerr2.Handle
for the cleanup. The first one,err2.Returnf
, annotates the error. Both are called when there is an err…