3 ms·
The readConfig example is not really an issue in go. Just return the io error and type switch after the readConfig. if config, err := readConfig(ioReader);
by zimbatm 12y ago
The readConfig example is not really an issue in go. Just return the io error and type switch after the readConfig.
if config, err := readConfig(ioReader); err != nil {
switch err.(type) {
case io.ErrClosedPipe:
// do one thing
case ParseError:
// do something else
case ...
}
}
- drdaeman 12y ago> Just return the io error Manually, on every function call that may fail - that was my only point why exceptions may result in a clearer code. section, err := parseSection(ioReader) if err != nil { return nil, err } Has some boilerplate, as compared to a typical exception-based section = parseSection(reader) // throws IOError
- zimbatm 12y agoYeah I get what you mean. If you forget that "throws" comment then the Java code is opaque to the exception. I think Go developer see a value in having errors exposed explicitly, it forces them to think about how to handle them instead of having a catch-all at the top of the program. But now we're down to philosophy and personal taste :)