Skip to content

feat: another improved error handling proposal #1018

Open
@peter7891

Description

@peter7891

I propose introducing a new keyword try to tackle the problem of if err !=nil spam.

Curretnly we have

func foo() error {
    f, err := openFile()
    if err != nil {
        .....
    }
    
    n, err := operateOnFile(f)
    
        if err != nil {
        .....
    }
}

This can quickly get out of hand.

I propose the code to look something like

func foo() error {
    f := try openFile()    
    n := try operateOnFile(f)
}

The way it will work is, try will be replaced by the normal error handling we have now, during preprocessing.
Many details are to be defined. This is just a conversation starter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gno-proposalGnolang change proposals

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions