Why no 'elif' in try/except?

John Roth johnroth at ameritech.net
Mon Jun 4 01:15:23 EDT 2001


Because it makes no sense?

The except clauses are for handling exceptions, the else
clause is for handling the case when everything worked fine.

Mixing the two makes no sense. In an except clause, there
is no result to test; in an else clause, there is. Is the elif supposed
to execute when there are exceptions, or when there aren't?
If it's simply an extension to the else clause, then I suppose it
doesn't harm anything, but it adds complexity to the language
definition. At this point in my life, I tend to agree with Einstein -
make everything as simple as possible, but no simpler. The last
place (or at least one of the many last places) I want additional
complexity is in exception handling.

John Roth

"Ype Kingma" <ykingma at accessforall.nl> wrote in message
news:3B1A29DE.9876770D at accessforall.nl...
>
>
> Carsten Gaebler wrote:
> >
> > Hi there!
> >
> > How about adding an 'elif' to try/except? I.e.:
> >
> > try:
> >   res = dosomethingnasty()
> > except:
> >   complain()
> > elif res == 1:
> >   behappy()
> >
> > instead of
> >
> > try:
> >   res = dosomethingnasty()
> > except:
> >   complain()
> > else:
> >   if res == 1:
> >     behappy()
> >
> > Any opinions?
>
> The 'else:' in 'try: except: else:' should have been called 'normally:'.
>
> Regards,
>
> Ype
>
>
> P.S. A possible cause of this problem is that sheep normally don't fly:
>
> try:
>   sheep.fly()
> except:
>   sheep.fell()
> normally:
>   ???
>
> P.P.S. Perhaps this code be preceeded by "while 1:" to make it more clear.
>
> --
> email at xs4all.nl





More information about the Python-list mailing list