All this talk about try: ... finally: and exceptions reminded me of a curious behavior I discovered a while back, i.e. that finally can swallow your exceptions. This is a contrived example, but shows the point:
def divide1(n1, n2): try: result = n1/n2 finally: print "cleanup" result = "Infinity\n" return result # the exception is swallowed away def divide2(n1, n2): try: result = n1/n2 finally: print "cleanup" result = "Infinity\n" return result # the exception is NOT swallowed away print divide1(10, 0) # no-exception print divide2(10, 0) # error If there is an indentation error in "divide2" and the return line is too indented the exceptions get swallowed by the finally clause. I am not sure if this is good or bad, but sure it surprised me that a finally clause could hide my exception. Michele Simionato _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com