Print traceback in C code

Thomas Heller theller at python.net
Thu Feb 6 11:30:41 EST 2003


I'm trying to print a traceback in C code.

According to some articles I found, mainly by Mark Hammond, it's
basically that I would have to write something like this in C

  import traceback, StringIO
  s = StringIO.StringIO()
  traceback.print_exception(tb_type, tb_value, tb_traceback, file=s)

and then call s.get_value() and convert it to a string.
I'm stuck, however, because calling

  PyErr_Fetch(&tb_type, &tb_value, &tb_traceback);

leaves a NULL pointer in tb_traceback, although tb_type and tb_value
are Python objects. Even calling PyErr_NormalizeException() doesn't
help.

What am I missing?

Thanks,

Thomas




More information about the Python-list mailing list