The finally clause will execute, whether there was an error encountered or not. : finally « Statement « Python Tutorial






try:
   v = int( raw_input("Enter a value: "))
   print "We got some valid input!"
   x = 100 / v
except (KeyboardInterrupt):
   print "well, ok, if you don't really want to.."
except ZeroDivisionError:
   print "You can't divide by ZERO!"
except:
    print "Some other error happened here"
else:
    print "All went well, x = ", x
finally:
    print "This is executed no matter what!"








3.11.finally
3.11.1.Using finally clauses.
3.11.2.Defining Clean-Up Actions
3.11.3.The finally clause will execute, whether there was an error encountered or not.