buggy python interpretter or am I missing something here?
me
noone at all.net
Mon Jan 27 01:02:00 EST 2014
On Mon, 27 Jan 2014 00:36:20 -0500, Dave Angel wrote:
> sys.exit() raises an exception, and you're deliberately eating
> that exception.
>
I can buy that sys.exit (may) be throwing an exception...My point of
contention isn't that I may be throwing one, but why would a subsequent
"raise" in the except: clause cause the point of program execution to
jump back up to the sys.exit(0) and then function correctly. This seems
to be a violation of the programming semantics of python as I understand
them...coming from an old fart c++ programmer where bare catch() is
totally acceptable and common form.
>
> Bare except is almost never a good idea. It's going to intercept
> the exit exception, plus control C, syntax errors and others.
> Which you'd have known if you printed the exception code.
>
>
> If you're going to catch an exception, be specific. Otherwise
> expect the unexpected.
>
>
> There is a hierarchy of exception classes, so you could catch a
> fairly generic class. But you do need to distinguish.
I'll take your point of "almost a never good idea" under consideration
and agree that if I was writing something for production use I'd be more
comprehensive, but I really don't care what exceptions are raised at this
point ... until I've tested with bunches of input data and see that it
does break and under what circumstances. But...it still doesn't explain
why/how a raise in the except: clause can recover the point of program
execution back to the sys.exit(0) that threw the exception.
Are you saying that the programming semantics of try/except are different
in python than they are in c++? My expectation being that when an
exception occurs program control jumps to the except: and then continues
below without ever going back to the code that threw the exception in the
first place...because that's exactly what it appears to be doing?
Are except: clauses in python more synonymous with the old BASIC "GOSUB"
or "ON ERROR GOSUB" statement rather than following the c++ semantics?
kind regards
More information about the Python-list
mailing list