Mega Code Archive

 
Categories / Python Tutorial / Statement
 

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."