Overriding a built-in exception handler
Jp Calderone
exarkun at divmod.com
Thu Jul 21 11:07:55 EDT 2005
On 21 Jul 2005 07:39:10 -0700, callmebill at gmail.com wrote:
>I'm having a tough time figuring this one out:
>
>
>class MyKBInterrupt( ..... ):
> print "Are you sure you want to do that?"
>
>if __name__ == "__main__":
> while 1:
> print "Still here..."
>
>
>So this thing keeps printing "Still here..." until the user hits ctl-c,
>at which time the exception is passed to MyKBInterrupt to handle the
>exception, rather than to whatever the built-in handler would be.
>
>I've Read-TFM, but I only see good info on how to create my own class
>of exception; I don't see anything on how to override an existing
>exception handler.
>
>Thanks in advance for any help.
See excepthook in the sys module documentation:
http://python.org/doc/lib/module-sys.html
Jp
More information about the Python-list
mailing list