3 ms·
Writing exception-safe code is non-trivial. There has been a lot of debate recently about whether exceptions are a mis-feature. The main worry is that if you al
by zik 13y ago
Writing exception-safe code is non-trivial. There has been a lot of debate recently about whether exceptions are a mis-feature. The main worry is that if you allow exceptions sensible-looking code can lead to many non-obvious bugs. This link gives some insight:
http://stackoverflow.com/questions/1853243/c-do-you-really-write-exception-safe-code/1853769#1853769 http://stackoverflow.com/questions/1853243/c-do-you-really-w...
Some more reasons why exceptions are problematic:
http://mortoray.com/2012/04/02/everything-wrong-with-exceptions/ http://mortoray.com/2012/04/02/everything-wrong-with-excepti...
Go's choice I think is very well considered. If reliability is important to you then I believe handling errors explicitly leads to clearer, more correct code.
- quatrevingts 13y agoThese criticisms of exception handling are primarily based on their implementation in C++; they are not issues inherent in exceptions. Exceptions are clearly more problematic when they are bolted-on after the fact to a language with manual memory management and a large existing body of code that is unaware of them. But writing exception-safe code IS trivial, in basically any language except C++. Garbage collection is all you need in most cases, and try-with-resources/RAII/etc takes care of closing I/O. Note that Go still needs defer() to reliably take care of the latter, so it's not clear to me what is gained by the omission (or rather, strong deprecation) of exceptions.