2 ms·
Depends on the language for me. If I'm in Java and need to put try-finally blocks for cleanup of non-memory resources, then error codes are cleaner. If I'm in
by MereInterest 10y ago
Depends on the language for me. If I'm in Java and need to put try-finally blocks for cleanup of non-memory resources, then error codes are cleaner. If I'm in C++, with all objects using RAII to clean up after themselves, then exceptions are the simple way to go.
- jjnoakes 10y agoEven with raii and exceptions, I find myself disliking exceptions. I like seeing which parts of my program can fail, and I want to be forced to consider what should happen in different failure scenarios. I like explicit error handling because not only is it obvious where my program can fail (and why), but it is obvious where it can't fail too. With exceptions, any line of code may fail. Or maybe not. It is all invisible. (Now this assumes a language that enforces return code checking; I use C and a static analysis pass today, but a few languages get this built-in).
- prodigal_erik 10y agotry-with-resources helps a lot, it basically invokes AutoCloseable.close for RAII-style cleanup.