2 ms·
When writing, say, a parser, I'd rather throw and catch exceptions. Which is also possible in Go, and template parser from its standard library is, actually, w
by dchest 15y ago
When writing, say, a parser, I'd rather throw and catch exceptions.
Which is also possible in Go, and template parser from its standard library is, actually, written in this style:
http://golang.org/src/pkg/template/parse/parse.go#L96 http://golang.org/src/pkg/template/parse/parse.go#L96
Functions call panic() (via t.errorf) to avoid passing errors between multiple levels of functions, but then Parse method catches it with recover(), checks what kind of error it is, and either panics again if it's a runtime error, or returns other kinds of errors.