> In C++ you can throw an exception, which will unwind the stack properly on
> the way out, and if main() doesn't catch it, then it calls abort(). C has
> no standard equivalent.
> /s/ Adam
Mmmh. So does this mean that C applications have quite a hard time when
they need to quit in a clean way when executing some code with a deep
call stack, right?
Exception handling is a double edged sword, you can cleanly unwind the stack but it may leave your program in a state you can't continue with, because your data structures are left in a state that's undefined. It can also introduce space leaks unless you follow certain rules. Experienced C++ programmers can use the language to write great code, but you tend to make a lot of mistakes before you become an experienced programmer.
Returning an error code and writing explicit error handling code at each level, the thing you typically do in C, may often work better. Google's Go language intentionally left exception handling out of the language.