classification
Title: traceback module docs should show how to print/fomat an exception object
Type: enhancement Stage: needs patch
Components: Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, amaury.forgeotdarc, r.david.murray
Priority: normal Keywords:

Created on 2012-04-23 21:22 by r.david.murray, last changed 2012-04-24 05:02 by Arfrever.

Messages (3)
msg159084 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-23 21:22
Suppose you have an exception object acquired from somewhere.  The exception is no longer active on the stack.  Now you want to format the exception like format_exception would (to log it, perhaps).  To do this you apparently need to call:

  format_exception(type(exc), exc, exc.__traceback__)

This seems redundant, so it would be nice to have a simpler call.  Too bad the name format_exception is already taken.  But, leaving that aside, the above is not documented in the traceback module.  The last example shows the (type(exc), exc) call form for format_exception_only, but that's as close as it gets.
msg159091 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-04-23 22:08
Why not reuse format_exception(exc)?
in 2.7 you could write "raise type, value, traceback", or "raise value".
I suggest that traceback.format_exception take the same route, and accept both (type, value, traceback) and (value).
msg159102 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-23 23:36
Sounds OK to me, though I am worried others will think that kind of variable signature (where the type of the first argument depends on the number of arguments passed) is bad.
History
Date User Action Args
2012-04-24 05:02:06Arfreversetnosy: + Arfrever
2012-04-23 23:36:49r.david.murraysetmessages: + msg159102
2012-04-23 22:08:45amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg159091
2012-04-23 21:22:51r.david.murraycreate