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.print_last fails
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6, Python 2.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, tzot
Priority: normal Keywords:

Created on 2008-01-17 13:26 by tzot, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit tzot, 2008-01-17 13:26 A test displaying the bad behaviour
traceback_patch.diff tzot, 2008-01-17 13:42 Patch for traceback.print_last()
Messages (3)
msg60028 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2008-01-17 13:26
traceback.print_last() depends on the existence of sys.last_type,
sys.last_value, sys.last_traceback, which don't always exist when
called. See attached example file. I will shortly send the patch for
msg60029 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2008-01-17 13:42
I haven't submitted a patch since the transition from to; I assume that I don't have to open a new patch for
this, but if I have to, please let me know and I will gladly do it.

The unified diff is attached; the test example I issued works with the
patched version.
msg60030 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-01-17 13:59
> traceback.print_last() depends on the existence of sys.last_type
Yes, that is exactly as documented:

>>> help(traceback.print_last)
Help on function print_last in module traceback:
print_last(limit=None, file=None)
    This is a shorthand for 'print_exception(sys.last_type,
    sys.last_value, sys.last_traceback, limit, file)'.

Furthermore, in the doc:
    "... they are set when an exception is not handled ..."
In your script, you *are* handling the exception. 
Your script really should use traceback.print_exc() instead.
BTW, your patch basically makes print_last() identical to print_exc()...
Date User Action Args
2022-04-11 14:56:29adminsetgithub: 46168
2008-01-17 13:59:20amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
messages: + msg60030
nosy: + amaury.forgeotdarc
2008-01-17 13:42:47tzotsetfiles: + traceback_patch.diff
messages: + msg60029
2008-01-17 13:26:57tzotcreate