else: w/o except: - why not?
Cameron Laird
claird at lairds.com
Tue Apr 1 11:41:08 EST 2003
In article <mailman.1049211247.3694.python-list at python.org>,
Michael Chermside <mcherm at mcherm.com> wrote:
.
.
.
>I can't speak for Tim, but my OWN opinion is precisely in alignment
>with what you have written.
>
>I think that a "bare except" is useful in only two ways. The first
>is like a "finally" clause that's skipped if everything works. In
>other words, the following bits of code is (almost[1]) equivalent to
>your second example:
>
> everythingWorked = False
> try:
> f1()
> everythingWorked = True
> finally:
> if not everythingWorked:
> f2()
>
>This doesn't come up much, but it's occasionally useful, and your
>version (using bare except with a raise) is a little prettier.
>
>The other situation is running "untrusted plug-in" code of some
>sort. Something like this:
>
> try:
> randomCodeSomebodyUploaded()
> except:
> logProblem()
>
>But really, that hardly EVER comes up. I wish that guido had made
>it harder to spell "bare except" because these situations seem so
>unusual. The next best solution is to just avoid it unless you're
>SURE you need it.
.
.
.
Thanks, Michael.
I'm rather obsessive on exceptions; I think programmers
generally misunderstand them and neglect their importance.
Very, VERY few programming texts do them justice; one ele-
ment of my enthusiasm for Alex's books <URL: http://
www.unixreview.com/documents/s=7822/ur0303j/ > is that he
speaks like an adult about them. Unless you've made a
disciplined survey of the extant literature, you won't
realize how rare this is.
I'm working on a couple of articles of my own to shift the
balance a bit.
I disagree with you on the frequency of "running 'untrusted
plug-in' code", or perhaps I misunderstand what you mean.
Briefly, I mistrust a LOT of code. Even when I'm using
well-known, mature extensions, my aim is to have at least
top-level error-handlers that catch *everything*. Are we
on the same subject?
--
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