Using finally clauses. : Finally : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Finally »

 

Using finally clauses.


def doNotRaiseException():
   try:
      print "In doNotRaiseException"
   finally:
      print "Finally executed in doNotRaiseException"

   print "End of doNotRaiseException"

def raiseExceptionDoNotCatch():
   try:
      print "In raiseExceptionDoNotCatch"
      raise Exception
   finally:
      print "Finally executed in raiseExceptionDoNotCatch"

   print "Will never reach this point"

print "Calling doNotRaiseException"
doNotRaiseException()

print "nCalling raiseExceptionDoNotCatch"

try:
   raiseExceptionDoNotCatch()
except Exception:
   print "Caught exception from raiseExceptionDoNotCatch in main program."



Leave a Comment / Note


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


PYTHON TUTORIALS

 Navioo Statement
» Finally