boB Stepp wrote: > I have not used a "finally" block before. I just had the thought that > maybe it would run even if an uncaught exception might occur. I tried > to test this thought by generating a deliberate NameError in the "try" > block and added a print to the "finally" clause. I got the intended > NameError with no evidence of the added print printing. But I thought > I would ask just to be sure: If an uncaught exception occurs, will > the "finally" clause execute?
Yes. >>> try: ... 1/0 ... except ValueError: ... print("not triggered") ... finally: ... print("ALWAYS TRIGGERED") ... ALWAYS TRIGGERED Traceback (most recent call last): File "<stdin>", line 2, in <module> ZeroDivisionError: division by zero If something seems too complex in your real code try to come up with a similar setup in the interactive interpreter (or use a minimal demo script if that proves impractical). _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor