Skip to content

errors... #10

Description

@PaperPrototype

Imagine the following syntax for errors

// this function will return an error or int32 (zig handles errors this way)
// I think zig uses a union?
func add(a, b int32) (int32, error) {
     return errors.New("This function failed")
}

func main() error {
    //
    result := add(0, 1) catch (err) {
        return err
    }

    log.Println("result:", result)
}

Idea:
If a function returns an error you must have to "catch" it. No more if err != nil

functions in C, C#, C++, Rust, Javascript, and Zig can only return 1 value. The problem was "how can you stick an error in there?" Go did the most obvious (and least creative thing) and just allows you to return multiple types. It's simple, and boring, just like go. I want to keep that spirit. It also forces "one way" of handling errors. Not sure of this syntax' implications but I like it.

It is not a "try catch" but uses the "catch" keyword which should be very familiar to developers.

Rust's approach is not pretty, but it works. It wraps errors and values in a Result type. I don't really like this as much as Zig's approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions