[Python-Dev] PEP 377 - allow __enter__() methods to skip the statement body

"Martin v. Löwis" martin at v.loewis.de
Sun Mar 15 20:38:57 CET 2009

> Note that using exceptions for control flow can  be bad for other
> implementations of Python. For example exceptions on the .NET framework
> are very expensive.

Why do you say that? What specific implementation of .NET are you
referring to? What do you mean by "very"?

> Isn't it better practise for exceptions to be used for exceptional
> circumstances rather than for control flow?

This is an ongoing debate (in Python, and outside). I'm in the camp
that says that exceptions are a control flow mechanism just like
loops, conditionals, and recursion. With exceptions, you get essentially
multiple alternative outcomes of a function call, rather than just a
single result. In principle, it would be possible to eliminate the
return statement altogether, but it is useful syntactic sugar.


More information about the Python-Dev mailing list