[Python-ideas] except expression
Steven D'Aprano
steve at pearwood.info
Mon Feb 17 06:12:34 CET 2014
On Sun, Feb 16, 2014 at 07:31:17PM -0800, Ethan Furman wrote:
> I see two motivating factors for an except expression:
>
> - one line try/except handling for simple cases
> - easier default value handling when function/method does not support a
> default value
>
> Given that, I don't think we need to support multiple exception types or
> chained exceptions. If it's that complicated, use an actual try block --
> it'll be much more readable.
I'm sympathetic to this view, but I think that by using appropriate
parentheses, multiple exception types and multiple exceptions are very
readable.
Of course, like deeply nested list comps or generator expressions, or
too many ternary-if expressions, you can obfuscate your code by abusing
this proposed syntax. The answer to that is, Don't Do That.
--
Steven
More information about the Python-ideas
mailing list