Mar-09-2019, 11:30 AM
You cannot catch SyntaxError, since it is raised prior code execution (i.e. before try and except are executed); If you use
eval
, you can be able to catch it, e.g.from sympy.abc import x, y code = """ e = x + y + x) """ try: eval(code) except SyntaxError: print("Hello")