re: Go 2 Draft: Error Handling VIEW POST

re: That doesn't work for returning errors, though. What if I wanted to return a wrapped version of the error?

Fair enough, but in that case, the wrapping is implicit and it looks like a twisted version of a try/catch block, something that spreads confusion.

I would prefer something like this:

func main() {
    check {
        hex := ioutil.ReadAll(os.Stdin)
        data := parseHexdump(string(hex))
    } handle err {
        switch err.(type) {
    case *os.ErrNotExist:
        // Code...
    case ...:
        // ...
        // ...

As its more structured, easier to read and less confusing than the draft proposal. Note that the handle could be triggered multiple times just as the original handle version.

But now there's very implicit error checking, you don't know which lines may result in an error, which is something the proposal was trying to avoid.

code of conduct - report abuse