I am writing a program where depending on input values, the code will terminate. That led me to think of the best way to implement this generally. I can easily come up with two examples:
if (bad_value) {
clean_up();
exit(1);
}
and something like this
try
myFunc();
catch myException {
clean_up();
exit(1);
}
int myFunc() {
if (badValue) throw myException;
...
}
The first code block seems much cleaner so I wonder why you would want to ever use exceptions? I guess this is really a battle of c
vs c++
.