3 ms·
> Error handling is a solved problem True. > exceptions Nope. Exceptions aren't capable enough; you really want conditions & restarts: http://gigamonkeys.co
by eadmund 8y ago
> Error handling is a solved problem
True.
> exceptions
Nope. Exceptions aren't capable enough; you really want conditions & restarts: http://gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html http://gigamonkeys.com/book/beyond-exception-handling-condit...
Conditions can be signalled, handled & resignalled like exceptions, except that they can be optionally ignored and handlers can optionally choose to restart. An exception unwinds the stack, while a condition is handled prior to unwinding, which means that the available recovery strategies are more numerous.
- nprateem 8y ago> Nope. Exceptions aren't capable enough They've been perfectly fine for the majority of popular languages and are a vast improvement over manually mimicking them the way most people do with Go.
- YorkshireSeason 8y ago"Right tool for the right job" Exceptions are an extremely useful and widely used tool for dealing cleanly with certain classes of errors (through a non-local jump out of a context to a dynamically bound target), let's call them simple errors. Maybe something that can be oversimplified like this: def main ( ... ) try ... catch case e => print "Something's wrong, aborting" (Note that in Go's original main use case (writing low-level servers), such simple error handling is rarely what's needed.) If you need restarts etc, then standard exceptions are not the right tool. In my experience, it's worthwhile to stop thinking about errors in such situations but see the behaviour that you are tempted to classify erroneous as part of the normal algorithm, using control constructs other than exceptions.