>>>>> "Roy" == Roy Smith <roy at panix.com> writes:
Roy> I think what you've demonstrated here is not so much that
Roy> exceptions are a bad thing, but that C++'s implementation of
Roy> exceptions (like most things in C++) is overly complicated. I find
Roy> it interesting that many people who come from a C++ background
Roy> (especially those who migrated from C) tend to dislike exceptions.
Roy> It must have been something in the water when they were growing up
Roy> :-)
In Python, function calls and returns are actually quite slow (because they
has to allocate a dictionary)---just like everything else. So the slightly
slower exception handling time does not add to the equation. In C++,
function calls and returns are extremely fast (they just add and subtract a
constant from the stack pointer and save the return address). While
exceptions are implemented in a way that is also "fast" (e.g., typical
implementation uses the faulting address to look up an "exception table" to
find the location where roll-back of variables are needed, and then look up
a table to find the handlers if any, and after that go up one level), it is
nowhere near a normal function returns. So in C++, exceptions are
considered heavy-weight. It is by no means that C++ exceptions are "overly
complicated": it is in fact less featureful than that of Python (e.g., no
stack trace is kept once you catch it, unlike in Python where you can
re-throw and still keep the stack trace). When you love speed, there is a
lot less that you can do.
Regards,
Isaac.