[Tutor] Scope of exceptions

Craig McDonald craig.a.mcd at googlemail.com
Wed Aug 5 12:34:28 CEST 2009


Howdy,

I am in the process of moving all my perl scripts to python and also
trying to learn to program rather than just know enough to automate
sections of my job. I am trying exit cleanly if I force the script to
exit early. I am working my way through core python but not yet read
properly about exceptions so this is how I guessed exceptions to work.

try:
    statements
    extractData()
    more_statements
    even_more_statements
except KeyboardInterrupt:
    exit('Exiting')

Once it enters/runs the extractData func and if I choose to exit
(control c) it throws an exception rather than exiting cleanly. Do I
need to put a 'KeyboardInterrupt' exception for every function?

Thanks in advance,

Craig


More information about the Tutor mailing list