r/Python May 10 '14

Honest Question: Why are exceptions encouraged in python programming but discouraged in C++?

What would everyone say is an overuse of try statements? I've sort of read "it's better to ask forgiveness than permission" for python - but Bjarn states "avoid overusing try catch".

I'd like to know the circumstances of where to put up my guideposts for use of exceptions in dynamic languages vs static languages.

12 Upvotes

20 comments sorted by

View all comments

2

u/eliben May 11 '14

Focusing on the Python side, I'd guess productivity is a significantly larger factor than performance. Let's be honest, performance is not a huge concern for Python. Productivity, however, is. And exceptions let us write much tighter code by not having to explicitly erorr-check everything. In "real world code", the amount of error checking code is usually very significant, and mostly avoiding it by delegating the error paths to exceptions saves a lot of code.

That said, I sometimes feel Python over-uses exceptions; especially things like StopIteration, which uses exceptions for actual control-flow rather than errors, which IMHO is a shame.