Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Proposes an exclamation identifier ! similar to the blank identifier for assignment. A non zero value assigned to ! causes a run-time error. For example:
Related to the try proposal this proposal aims to simplify error boilerplate. Unlike the try proposal it can be used for any type. The value v assigned to ! effectively calls:
I think this behaviour is similar to how type assertions panic on invalid non handled cases.
As a larger example Go by Example: Reading Files could be written as:
This removes the check function and calls to check. The panic stack trace would be simplified as the call to check is removed. I could see this being used for example code and simple scripts where panics are already used for error handling.
FYI, allowing a special character in place of an error variable is one of the most common suggestions to simplify error handling. I think I was the first to suggest it, but it's appeared in many flavors since. Some are on https://github.com/golang/go/wiki/Go2ErrorHandlingFeedback#recurring-themes