by barrkel · 16y ago · 0 comments
I do find it interesting, however, that the manual error propagation scheme is functionally identical to simple exception handling when followed rigorously. Without standard error types it has similar problems; pattern matching of some kind wouldn't go amiss.
The alleged advantage of using error codes (aside from explicit code flow, already hurt by panic) over exceptions is similar to Java's mistake of exception specifications, encouraging people to deal with errors at a low level (usually wrong IMHO) and making it a pain to pass the unobfuscated error up the stack for logging / user display.
Panicking across package boundaries is unidiomatic, a bad idea, and explicitly warned against in the blog post.
The problem is at its heart the notion of an exceptional situation. Whether a condition met by a library is exceptional usually depends on how it is used by its caller, which may be many stack frames away. The library either needs to ask its caller if it should really ignore this error (which probably came from another library again, maybe file I/O or network, etc.). The usual alternate choices are unilateral abortion (raise an exception, or conscientiously propagate an error code) and unilateral ignoring (which is the alternative Go seems to be trying to offer). If Go really wanted to enable handling problems at this low level rather than propagating to higher levels like exceptions do, it might have implemented a restartable condition system; this would have let the library give the higher level module the choice. But Go didn't do that.