Try..Except..Else

jredford@lehman.com
Fri, 10 Dec 93 20:03:19 -0500

>> > My proposal is to add an 'else:' statement to the try:except: statement.
>> > This statement would only be executed if the try: succeeded. This would be
>> > consistent with the while:else: statement and for for:else: statement. The
>> > code fragment would become:
>> >
>> > try:
>> > file = open('...', 'r')
>> > except:
>> > data = process_something_else()
>> > else:
>> > data = process_file(file)
>>
>> Brilliant!

Hmm, I'd say rather, deranged. Why bother to have exceptions if you
treat them like this?

try:
file = open('...', 'r')
data = process_file(file)
except IOError:
data = process_something_else()

Is proper. the 'else' version is better written:

if (file = open('...', 'r'))
then
data = process_file(file)
else
data = process_something_else()

If you want to execute code UNconditionally after a try block, use
Try..Finally. If you want code to only execute if a exception dosent
happen, then thats what the try body is for.

--
John Redford (AKA GArrow) | 3,600 hours of tape.
jredford@lehman.com       | 5 cans of Scotchguard.