[Tutor] How to test for the existence of a table in a sqlite3 db?
Peter Otten
__peter__ at web.de
Sun Oct 15 04:09:08 EDT 2017
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).
More information about the Tutor
mailing list