[go-nuts] Re: “Normal” vs. “error” (control flow) is a fundamental semantic distinction

2022-05-30 Thread Harri L
Thank you!

Indeed, the selected names follow the try/catch idiom, and with the 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 

 
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 

:
"*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 写道:
>
>> 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(, "copy %s %s", src, dst)
>>
>> r := try.To1(os.Open(src))
>> defer r.Close()
>>
>> w := try.To1(os.Create(dst))
>> defer err2.Handle(, func() {
>> _ = os.Remove(dst)
>> })
>> defer w.Close()
>>
>> try.To1(io.Copy(w, r))
>> return nil
>> }
>>
>> The playground .
>>
>> A couple of blog posts about the subject:
>>
>>- Error Propagation 
>>
>> 
>>- Errors as Discriminated Unions 
>>
>>
>> I'm the author of those posts and the err2 package 
>> . 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.


[go-nuts] Re: “Normal” vs. “error” (control flow) is a fundamental semantic distinction

2022-05-25 Thread Zhaoxun Yan
Try & Catch sounds great!

在2022年5月19日星期四 UTC+8 00:15:09 写道:

> 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(, "copy %s %s", src, dst)
>
> r := try.To1(os.Open(src))
> defer r.Close()
>
> w := try.To1(os.Create(dst))
> defer err2.Handle(, func() {
> _ = os.Remove(dst)
> })
> defer w.Close()
>
> try.To1(io.Copy(w, r))
> return nil
> }
>
> The playground .
>
> A couple of blog posts about the subject:
>
>- Error Propagation 
>
> 
>- Errors as Discriminated Unions 
>
>
> I'm the author of those posts and the err2 package 
> . 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/27a9b63c-ad67-475d-851a-97fadb94b3dfn%40googlegroups.com.