The finally clause will execute, whether there was an error encountered or not. : Finally : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Finally »

 

The finally clause will execute, whether there was an error encountered or not.


try:
   v = intraw_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!"



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Finally