else: w/o except: - why not?
Cameron Laird
claird at lairds.com
Tue Apr 1 09:50:19 EST 2003
In article <mailman.1049156943.12744.python-list at python.org>,
Tim Peters <tim.one at comcast.net> wrote:
.
.
.
>> try:
>> # some code that may except
>> except:
>> # and if it does, then, okay, just ignore it
>> pass
>> else:
>> # but if it didn't except, I want to do this
>
>Now I know what you intended, assuming you wrote what you meant. Reason
>enough for me. If you want the absence of an except clause to imply the
>presence of a catch-everything except clause, there's really no chance: a
>bare except is bad practice. For example, it catches SystemExit and
>KeyboardInterrupt too, and bare excepts rarely *intend* to catch those.
>Guido isn't going to make it easier to write poor code.
>
>
I'm leaving aside Mr. Hand's goals; I'm still unsure about them.
I want to be clear about the judgment that "a bare except is bad
practice". Are you talking about any unqualified except? Is
try:
f1()
except ZeroDivisionError:
f2()
except:
f3()
an instance of "a bare except" in the sense that you intend here?
And, for you, does
try:
f1()
except:
f2()
raise
become *not* bad practice?
--
Cameron Laird <Cameron at Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html
More information about the Python-list
mailing list