I notice at least three things from your proposed syntax:

1. Passing a *type* as an argument ("os.PathError"), rather than a *value 
of a type*
2. A control structure.  This might involve passing a block of code as a 
hidden argument (like blocks in Ruby), or some sort of macro expansion.
3. The syntax "pathError -> fmt.Println"; I can't see what this is supposed 
to do.

I don't know which of these (or all of them) is critical to your idea, but 
I think they need to be identified separately.

On Sunday, 19 September 2021 at 10:33:00 UTC+1 Haddock wrote:

>
> I like the way error handling is done in the xerror package. Things become 
> more concise, but remain very easy to read and understand as in plain Go 
> errorhandling.
>
> Here is the example of how to use xerror.As:
>
> _, err := os.Open("non-existing")
>     if err != nil {
>         var pathError *os.PathError
>         if xerrors.As(err, &pathError) {
>             fmt.Println("Failed at path:", pathError.Path)
>         }
>     }
>
> My idea is to make this even shorter like this:
>
> _, err := os.Open("non-existing")
> myerrors.As(err, os.PathError) {
>      pathError -> fmt.Println("Failed at path:", pathError.Path)
> }
>
> Think something like that has so far not been suggested. That's why I 
> thought it is justified to drop comment.
>
> myerrors.As would also do the check if err is nil. The code in my sample 
> is not valid Go code, I know. It is only pseudo code to show the idea.
>
>

-- 
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/c78b4db8-f175-49b3-a8bb-756b0fabac51n%40googlegroups.com.

Reply via email to