What's the best way to wrap a whole script in try..except?
Hari Sekhon
sekhon.hari at googlemail.com
Wed Jun 21 07:34:26 EDT 2006
Jon Ribbens wrote:
> In article <mailman.7287.1150885369.27775.python-list at python.org>, Hari Sekhon wrote:
>
>> I want to wrap a whole script in try ... except. What is the best way of
>> doing this?
>>
>
> You could do this maybe:
>
> import sys
>
> def excepthook(exc_type, exc_value, tb):
> import modules_needed_to_notify_exception
> ...
>
> sys.excepthook = excepthook
>
> import modules_needed_by_script
> ...
>
I've been trying this out and your method is by far the best I've seen.
This is overriding the default exception handler.
I don't know the deep magic yet but it works nicely. Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060621/692dedaf/attachment.html>
More information about the Python-list
mailing list