Message328796
When embedding Python into a C/C++ based programs, one of the ways to access the formatted traceback is/was to get the type, value and tb by calling the C API PyErr_Fetch() and then call native Python traceback.format_exception() function to get a list of strings representing the tracback.
This worked fine in 2.7.
Doing the same in 3.5 doesn't work because:
1. PyErr_Fetch()'s middle output argument 'value' is not an instance of Exception (or a subclass), but rather (what seems to me) a __str__ or __repr__ (i.e. the type is str) of said raised exception.
An aside - this seems to be the case both in 2.7 and 3.5, but differs (in both 2.7 and 3.5, I believe) from what sys.exc_info() returns, as there the middle output 'value' is of an Exception (or a subclass) type.
2. In the overhauled traceback module in 3.x, functions like format_exception() now use an internal class TracebackException which expects the exc_value (which it gets from format_exception()'s value argument) to be an instance of Exception (or a subclass), thus feeding traceback.format_exception() whatever I got from PyErr_Fetch() ends up throwing another exception.
As a temporary workaround, I can use traceback.format_tb() which luckily doesn't use the TracebackException class and works fine in 3.5. |
|
Date |
User |
Action |
Args |
2018-10-29 08:59:54 | tomasheran | set | recipients:
+ tomasheran |
2018-10-29 08:59:54 | tomasheran | set | messageid: <1540803594.22.0.788709270274.issue35103@psf.upfronthosting.co.za> |
2018-10-29 08:59:54 | tomasheran | link | issue35103 messages |
2018-10-29 08:59:53 | tomasheran | create | |
|