Exceptions vs Error Codes
Posted Mar 30, 2012 22:01 UTC (Fri) by khim
In reply to: Exceptions vs Error Codes
Parent article: Go version 1 released
On the other hand, exceptions tend to work nice when you have to repeatedly call library functions that almost always work as intended (that is, errors are really exceptional). In that case you can save a lot of error checking and write simpler code.
Yup. And as added bonus it'll guarantee your future employment when you'll find and fix dozens of security bugs and DOS cases.
4. Program defensively, specially when holding resources (open files, locks, connections, memory). Expect unexpected exceptions everywhere. Your code will probably have a longer and more interesting live than you expect.
This is what makes exceptions pointless. It's hard enough to find programmers which can correctly programs the common case. Someone who can correctly program all the exceptional codepaths will be usually too expensive. And will still miss some cases.
This is where fork(2) solution saves your beacon: sure, you still need to somehow handle cases where some shared resources (such as pipe or shared memory) misbehaves because other process died but most of the heavy lifting will be done by OS without your direct involvement: sockets will be freed, files will be closed and removed (you do remove temporary files right after open(2) call, because you need to handle poweroff case, right?), etc.
Go is trying to create something like this in a single process - but I'm not 100% sure how well it'll work.
to post comments)