4 ms·
In my opinion, this is not an issue with exception handling. It's an issue with bad programmers. You can dumb it down as much as you want, people are still goi
by simias 14y ago
In my opinion, this is not an issue with exception handling. It's an issue with bad programmers.
You can dumb it down as much as you want, people are still going to screw it up.
And you have exactly the same issue with "classical" error handling: you have to undo the partial job. Here's a bit of C code I wrote just this morning which closely ressembles your example:
for (i = 0; i < pdata->overlay_nr; i++)
if ((ret = overlay_init(data, i))) {
while (i--)
overlay_destroy(data, i);
goto overlay_err;
}
No exceptions, but I still have to remember to clean up before I dispatch the error.
I use exception quite a bit in C++, but it does fit my coding style. I use RAII almost exclusively, which alleviates most of the issues. That means that I don't have try{}catches everywhere, mostly only when I want to do actual error handling.
Exceptions are a tool, it's up to you to use it correctly (or not use it).