This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: traceback module docs should show how to print/fomat an exception object
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8
Status: closed Resolution: duplicate
Dependencies: Superseder: Expand traceback module API to accept just an exception as an argument
View: 26389
Assigned To: docs@python Nosy List: Arfrever, amaury.forgeotdarc, docs@python, iritkatriel, r.david.murray
Priority: normal Keywords:

Created on 2012-04-23 21:22 by r.david.murray, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
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.
msg380338 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-11-04 16:23
As of 3.5 there is this option:


Perhaps that can be mentioned in the doc for traceback.format_exception().
msg384659 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-01-08 13:12
In issue 26389 the api was changed so that now format_exception(exc) works.
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58860
2021-01-08 13:12:48iritkatrielsetstatus: open -> closed
superseder: Expand traceback module API to accept just an exception as an argument
messages: + msg384659

resolution: duplicate
stage: needs patch -> resolved
2020-11-04 16:23:03iritkatrielsetversions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3
nosy: + iritkatriel, docs@python

messages: + msg380338

assignee: docs@python
components: + Documentation
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