Get Stack Trace in “except” Block

6 thoughts on “Get Stack Trace in “except” Block”

I am trying to log execeptions using a try/except block and I was wondering if anyone has any sample code for extracting a stack trace from the exc_info() call.

Most examples on the web make use of the “traceback” module for getting stack traces. This module is not included with the embedded 1.5.2. Telit python. At the very least, it would be nice to extract the module name and line number of where the execption occurred.

There is an example in Telit Python Examples r3 in Download Zone, traceback_1.py file:

def tb_lineno(tb): # Coded by xxxxxxx from the example of PyCode_Addr2Line() # in compile.c. # Revised version by yyyyyyy to work with JPython too. c = tb.tb_frame.f_code if not hasattr(tb.tb_frame.f_code, ‘co_lnotab’): return tb.tb_lineno

We use cookies to enhance your browsing experience and help us improve our websites. To improve our website, we carefully select third parties that use cookies to allow us to serve specific content and achieve the purposes set out in our cookie policy. For more information on how to make adjustments through your browser to the cookies being used on your device, please click Find Out More link. By closing this banner or continuing to browse our website, you agree to our use of such cookies. FIND OUT MORE