[Python-ideas] except expression

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Feb 18 16:41:21 CET 2014


On Tue, Feb 18, 2014 at 10:30 AM, Rob Cliffe <rob.cliffe at btinternet.com>
wrote:
>
> Sorry, but this seems to me to be a futile discussion.
> Expressions can contain functions.
> Functions can raise any exception they like.
> So evaluating an expression can raise any exception you care to name.


This is true, but it does not follow that you need to be able to catch "any
exception you care to name" in the expression.

Exceptions that are caused by conditions not obvious from the expression
are better handled at a higher level.

Let's focus on the main use cases.  E.g. a better spelling for

x = d.get(key, default) -> x = d[key] except default
try: x = 1/y except ArithmeticError: x=0; -> x = 1/y except 0

etc.


I would not mind

 x = 1/f(y) except 0

not catching a TypeError that may come from f(y) in most cases.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140218/2b1ac254/attachment-0001.html>


More information about the Python-ideas mailing list