catching errors in embedded Python on Windows

Mark Hammond MarkH at ActiveState.com
Fri Aug 24 03:54:39 EDT 2001


Howard Lightstone wrote:

> OK, I made up a Python class/methods to take over stderr/stdout when
> running Pythonw applications and display them in a Tkinter window.
> Works slick.
> 
> However, this DOESN'T work when embedding Python since pythonrun.c still
> refers to stdout/stderr directly...which Windows doesn't have set to
> anything useful.
> 
> How does one reroute/catch these errors?  Unfortunately, the only thing
> I can think of  involves changing pythonrun.c to use the 'objects'
> attached to sys.stdout and sys.stderr so they COULD be rerouted.
> 
> It seems to me someone on this list commented on catching these embedded
> errors but I can't seem to find it.

Execute all of your "user" or "application" Python code inside your own 
, Python implemented exception handler.  This handler can catch all 
errors, and use the traceback module to print the exception details 
anywhere it likes.

This is the approach taken by Pythonwin and IDLE, to name just a couple 
I am familiar with...

Mark.




More information about the Python-list mailing list