[Python-ideas] except expression
Steven D'Aprano
steve at pearwood.info
Wed Feb 19 11:01:50 CET 2014
On Wed, Feb 19, 2014 at 07:29:00PM +1100, Chris Angelico wrote:
> On Wed, Feb 19, 2014 at 7:14 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> > I think it will be helpful to include a section with a few definitions,
> > because the term "chaining" is ambiguous. It could mean either:
> >
> > * Multiple except clauses in a single expression
[...]
> > Or chaining could mean wrapping one except-expression inside another,
> > such as:
> >
> > (expression except SpamError: spam) except EggsError: eggs
> >
> > which has two expressions each with three operands
[...]
> > I think it is important to decide which one is chaining, and which one
> > is not, include it in the PEP as a definition, and stick with it. I
> > *strongly* suggest that chaining means the second case.
>
> I've been using it to mean the first case. The second case is simply
> what happens when you use an except-expression as an operand to
> another except-expression, and I'd be inclined to call that "nesting",
Nested expressions is also a good term for it.
[...]
> But if that form is called "chaining", then what's the other form
> called? Whatever it is, I need a word for it, because that one is the
> one that entails additional syntax.
I don't think it needs a single word, especially since it's being
deferred for later. I'm partial to describing it as "multiple except
clauses", since that's exactly what it is.
As far as I can tell, nobody refers to this as exception chaining:
try: this
except A: a
except B: b
except C: c
...
Exception chaining is something very different, "raise A from B", and I
think it is harmful for comprehension to have "exception chaining" and
"chained excepts" mean radically different things.
> I'm okay with changing the word, but I need something to change it
> _to_. I can't just 'del chaining' - without some other reference, the
> whole concept would be garbage collected :)
Yes, but it doesn't have to be a single word.
--
Steven
More information about the Python-ideas
mailing list