Automatic exception catching and handling in Python

Hello,
I would like to know if there is a way pipe all exceptions and bugs in my program directly in a log file.

I already have a function to write in a log, but if an exception or bug occurs in a part of my program I didn't expected, the end user will see it, while I would like to hide it and keep it in a separate file which will be sent to the network administrator.

Any idea ?

Cordially

···

_________________________________________________________________
Mettez Messenger sur votre mobile !
http://www.messengersurvotremobile.com

Hello,

Hello,
I would like to know if there is a way pipe all exceptions and bugs in my program directly in a log file.

I already have a function to write in a log, but if an exception or bug occurs in a part of my program I didn’t expected, the end user will see it, while I would like to hide it and keep it in a separate file which will be sent to the network administrator.

Any idea ?

If you want to be able to catch all unhandled exceptions you can do some thing like the following.

Define an ExceptionHook method with the follwing argurments

def myExceptionHook(exception_type, value, traceback):

Do what you need to with exception info

Then sometime during the intialization of you program

import sys

sys.excepthook = myExceptionHook

This way everytime an unhandled exception is raised your method will be called to process it.

Cody

···

On 7/8/08, Phil Mayes olivebr@olivebr.com wrote:

At 08:15 AM 7/8/2008, you wrote: