[Python-ideas] why not try without except?
ben+python at benfinney.id.au
Sat Apr 25 11:12:11 CEST 2009
spir <denis.spir at free.fr> writes:
> Actually, this shows that 'try' alone can be considered analog to 'if'
> without 'else' clause
And without a condition, or a branch. Remember that ‘if’ introduces a
branch point, whereas ‘try’ does not.
> needed when the condition may raise an exception.
But there *is* no condition in a ‘try’ statement.
If what you mean is “when the suite introduced by ‘try:’ may raise an
exception”, that's true of just about every interesting statement in
Python: an exception might be raised at any point.
> Both express an optional action.
No. The suite that follows ‘try’ will be executed, just as surely as a
suite *not* enclosed in ‘try’.
> This could be written more directly, because we do not need the condition:
> ? <do_something>
> option <do_something>
> with the meaning: "Try & do this, but if there's an exception just let
> it down."
What does “let it down” mean?
If you mean “if there's an exception raised, just let it propagate up”,
that's what happens *without* a ‘try’. So I can only assume you mean
I don't understand the behaviour you describe. Perhaps if you would
explain what you think the difference should be between:
How should the behaviour differ?
\ “It takes a big man to cry, but it takes a bigger man to laugh |
`\ at that man.” —Jack Handey |
More information about the Python-ideas