[Patches] [ python-Patches-409097 ] sys.excepthook

noreply@sourceforge.net noreply@sourceforge.net
Sun, 18 Mar 2001 15:33:27 -0800


Patches item #409097, was updated on 2001-03-16 04:47
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=409097&group_id=5470

Category: core (C code)
Group: None
Status: Open
Priority: 5
Submitted By: Ka-Ping Yee (ping)
Assigned to: Nobody/Anonymous (nobody)
Summary: sys.excepthook

Initial Comment:
This patch separates out the traceback-displaying
functionality of PyErr_PrintEx into a new routine,
PyErr_Display(exc, val, tb).  PyErr_PrintEx finds and
calls sys.excepthook, and the new function
sys.excepthook calls PyErr_Display.

This allows user customization of top-level exception
handling (in particular, you can write Python routines
to install as sys.excepthook that display function
arguments or format tracebacks nicely in HTML for CGI
scripts).

This is a minimal patch just to implement
sys.excepthook.
A more complete patch, postponed for 2.2, factors out
the SystemExit handling in PyErr_PrintEx into a
separate
routine and replaces all of the C code in PyErr_Display
and PyTraceBack_Print with shorter, more maintainable
Python code in the traceback module.

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2001-03-18 15:33

Message:
Logged In: NO 

PS-- I would suggest to store a copy in sys.__excepthook__, just like sys.__stdout__.

Guido (too lazy to log in on SF)

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-03-18 15:10

Message:
Logged In: YES 
user_id=6380

Very close.  Thanks, Ping!

Mandatory improvement:most of the times where you use fprintf(stderr, ...) you should be using 
PySys_WriteStderr(...). The only time when it's OK to use stderr directly is is when sys.stderr is not found.

An idea which I'm not sure of: maybe the PyErr_Display() function could take a PyObject * 4th argument being 
the file object to which the traceback should be written.  This makes the logic of its callers a bit more convoluted, 
unless you let it default to NULL (which might be the best thing anyway).

Also...  I guess we need a few lines of documentation for sys.excepthook, for PyErr_Display(), and for the changed 
semantics of PyErr_Print[Ex]().

----------------------------------------------------------------------

Comment By: Ka-Ping Yee (ping)
Date: 2001-03-16 04:50

Message:
Logged In: YES 
user_id=45338

Upload got botched.  Trying again.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=409097&group_id=5470