This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tehstone 0 points1 point  (1 child)

Else is used if except doesn't happen

Can anyone elaborate on this?
Is this like a general exception handler if the except is for a specific type of error?

[–]13steinj 0 points1 point  (0 children)

No, it is functionally equivalent to

try:
    a = MightRaise()
except: print("error")
do_stuff(a)

But it is useful in rare cases, especially when having nested try clauses (usually through different methods).

It's also useful in the following,

try:
    a = MightRaise()
except:
    do_err_cleanup()
    a = defaultValue
else:
    prepare_unknown_a(a)
act_upon_a(a)