[Python-ideas] chained try (was Re: "maybe import"?)
Andrew Barnert
abarnert at yahoo.com
Sun Dec 29 23:21:08 CET 2013
On Dec 29, 2013, at 1:41, spir <denis.spir at gmail.com> wrote:
>> "except try" looks horrible, but I can't think of anything better.
>
> I would buy (if cheap!):
>
> try:
> stuff
> else try:
> other stuff
> else try:
> different stuff
> except Exception as e:
> deal with it
The advantage of "except try" is that it leaves the door open for specifying only certain exceptions instead of all, which would be useful in some cases.
But the advantage of "else try" is that it closes that door, eliminating most of the other questions I and others raised. It's clearly pure syntactic sugar with no ambiguity. Maybe that's a better idea.
More information about the Python-ideas
mailing list