People defending C++ exceptions for flow control are why we can't have nice things.
Conversation
Replying to
Python's exception-based iterator protocol bothers me. Instead of signalling the end by returning None, they throw StopIteration. Every for loop is basically this:
while True:
try:
value = next(iterator)
except StopIteration:
break
Replying to
You can do next(iter, None) to be fair, but even exceptions for flow control in Python are really annoying. Plus there's no way to distinguish "value is None" and "did not return a value" and "exception occured".
2
It just gets even worse for C++ because it's optimized for zero-cost exception handling and has to unwind the stack for any operation done in a try/except block (an implementation detail but in GCC/Clang/MSVC). For speed on the "correct" path, C++ incurs major performance hits.
1
Show replies

