2 ms·
To be fair, removing the assignment altogether in your example ignores the error much less explicitly than `try { myFunc(); } except { pass; }`
by cderwin 10y ago
To be fair, removing the assignment altogether in your example ignores the error much less explicitly than `try { myFunc(); } except { pass; }`
- Zikes 10y agoIf you remove the err assignment the compiler will also complain about a value assignment mismatch: https://play.golang.org/p/UBL0MZtscc https://play.golang.org/p/UBL0MZtscc > tmp/sandbox307381845/main.go:8: multiple-value "html/template".New("foo").Parse() in single-value context You would have to explicitly assign the err return value to underscore in order to ignore it.
- hueving 10y agoNo, remove the entire assignment.
- cderwin 10y agohueving is correct, I meant something like this[1]. Of course, something like this[2] also works. [1] https://play.golang.org/p/igdUx6qckf https://play.golang.org/p/igdUx6qckf [2] https://play.golang.org/p/_JW5QE_zOJ https://play.golang.org/p/_JW5QE_zOJ
- Zikes 10y agoThat function does not have side effects, so it would be pointless to remove the assignment altogether. Assigning errors to underscore is effectively the same as try { myFunc(); } except { pass; }, making them equivalent.