[Python-ideas] except expression

MRAB python at mrabarnett.plus.com
Tue Feb 18 16:13:30 CET 2014


On 2014-02-18 14:27, Alexander Belopolsky wrote:
>
> On Tue, Feb 18, 2014 at 9:07 AM, Paul Moore <p.f.moore at gmail.com
> <mailto:p.f.moore at gmail.com>> wrote:
>
>     Also, "expr except fallback" is a very simple case of a keyword-based
>     binary operation.
>
>
> I agree and ISTM a natural generalization of this to allow exception
> type specification would be
>
> expr except(Exc1, Exc2) fallback
>
Do you mean that the exception type would be optional? If so, then
using parentheses would be a problem because the fallback itself could
be in parentheses.

> or
>
> expr except[Exc1, Exc2] fallback
>
> I am not sure if any of these have been proposed, so apologies if they were.
>
> This said, I would still prefer the variant with the column as the
> closest to the existing syntax.
>
Another possibility would be to say that a bare except in an expression
catches only certain "expression-oriented" exceptions, e.g. ValueError.
The simplest way to do that would be to make them subclasses of an
ExpressionError class. The question then becomes one of which
exceptions are "expression-oriented"...



More information about the Python-ideas mailing list