Skip to content

Instantly share code, notes, and snippets.

View mathieudevos's full-sized avatar

Mathieu Devos mathieudevos

View GitHub Profile
@mathieudevos
mathieudevos / CheckHandleScoped.md
Last active July 17, 2019 05:04
Go2 Error Handling proposal: Check/Handle as TryCatch Scoped

Go2 Error Handling Proposal: Scoped Check/Handle

Based on the current proposals and counter proposals in: (Go2ErrorHandlingFeedback)[https://github.com/golang/go/wiki/Go2ErrorHandlingFeedback] I have concerns that the current proposed check/handle does create a code mess where it becomes extremely hard to follow the logic.

My proposal is to add the option to have fully scoped blocks as well as requiring the handle to scoped, and enforce the variable assignment already used in golang. Finally the handle would move to the bottom, to maintain the logic of top to bottom programming logic (which the original check/handle breaks).

A simple example could be the following:

check {
	foo := check FunctionThatReturnsErrorAsLast() // returns var, err