|
|
|
|
|
by luriel
5195 days ago
|
|
If panic/recover is the same as exceptions, why does everyone whine about the lack of exceptions? The fact is that while in theory panic/recover are mostly equivalent to exceptions, in practice they are very, very different. Panic is only used in truly extreme situations (like running out of memory) or programmer errors, and you can pretty much write code ignoring it. Most programs at most will need to call recover() once. Compare this with how exceptions are used in most languages where they are a fundamental aspect of a library's API. Also the way defer() reliably and cleanly handles cleanup is much more pleasant than exception and 'finally'. As for C macros, good C programmers have known for a long time that they are best avoided as much as possible. |
|
Anyway, Go does have exceptions. It just doesn't make much use of them. Seems a shame to not use a useful feature, but oh well.
defer is not reliable if you forget to call it. RAII is much more foolproof than defer in this way. You can forget to call defer, but you can't easily forget to call the destructor.