Thank you! Indeed, the selected names follow the try/catch idiom, and with the err2 <https://github.com/lainio/err2>, you can write code that includes non-local control flows. I hope that err2 is not confused with exception handling.
The Go2 try-proposal <https://lifesaver.codes/answer/proposal-a-built-in-go-error-check-function-try-32437> speaks about a helper library needed to get every help that try-macro could offer. The err2 package has that library now, and thanks to generics, the try-API is almost similar to try-macro. I know many didn't like the try-proposal, but what has been a considerable surprise is how much benefit you get when merging panics and errors. Rus Coxx: Error Handling -- Problem Overview <https://go.googlesource.com/proposal/+/master/design/go2draft-error-handling-overview.md> : "*Panics. We’ve spent a while trying to harmonize error handling and panics, so that cleanup due to error handling need not be repeated for cleanup due to panics. All our attempts at unifying the two only led to more complexity*." Then harmonization is now done with err2-package. On Wednesday, May 25, 2022 at 2:15:18 PM UTC+3 yan.z...@gmail.com wrote: > Try & Catch sounds great! > > 在2022年5月19日星期四 UTC+8 00:15:09<har...@gmail.com> 写道: > >> Hi all, >> >> I thought now was the time to go public. The automatic error propagation >> is possible with the help of a simple Go package, and it has been about >> three years now: >> >> func CopyFile(src, dst string) (err error) { >> defer err2.Returnf(&err, "copy %s %s", src, dst) >> >> r := try.To1(os.Open(src)) >> defer r.Close() >> >> w := try.To1(os.Create(dst)) >> defer err2.Handle(&err, func() { >> _ = os.Remove(dst) >> }) >> defer w.Close() >> >> try.To1(io.Copy(w, r)) >> return nil >> } >> >> The playground <https://go.dev/play/p/bUGX8yDAeoL>. >> >> A couple of blog posts about the subject: >> >> - Error Propagation >> >> <https://hackernoon.com/golang-more-error-handling-with-less-checking-eeh31go> >> - Errors as Discriminated Unions >> <https://hackernoon.com/billion-dollar-mistake-in-go-ll1s3tkc> >> >> I'm the author of those posts and the err2 package >> <https://github.com/lainio/err2>. Additional sources for original ideas >> are mentioned in the blogs and the package documentation. And, of course, >> pure error values are needed when transporting errors through channels. >> >> I hope that any gopher who tries the err2 package finds it as valuable >> and productive >> as we have. Indeed, Go is one of the most pragmatic and refactor-friendly >> native languages. >> >> Best regards, >> -Harri >> > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/397750bd-9028-4165-9cbd-3a8406e42c94n%40googlegroups.com.