2 may
2021

Catch/trap error in Python code.InteractiveConsole

I have embedded a code.InteractiveConsole in a gui which works fine. I would like to trap (or read) errors to be able to send a error popup/message box but I can't seem to trace or trap errors in the console. I can redirect the stderr.write output to a function, but that triggers many errors as the stream is written to in chunks. Is there some good way to achieve this? For example this code below does not trap errors (although printed to stdout).

import sys
from code import InteractiveConsole

con = InteractiveConsole()
try:
    con.push('1/0')
    print('No error caught')
except:
    print('Error caught')

print(sys.exc_info())

COMENTARIOS

DEJA TU COMENTARIO

© 2017 website by Rubit Corporation