global exception catching
Mark McEahern
marklists at mceahern.com
Thu Feb 27 08:45:33 EST 2003
[Hilbert]
> Is there a way to catch a "global" exception in a python
> program (meaning that if there would be an error
> during execution it could call a function before exiting)?
>
> I have a program that creates large temp files and in case
> of any unforseen problems I still need to clean up before
> exiting.
Well, for starters, help me understand why this won't work:
#!/usr/bin/env python
# yourprogram.py
def main():
try:
dostuff()
finally:
cleanup()
if __name__ == '__main__':
main()
-
More information about the Python-list
mailing list