+ 2
PY - except SyntaxError
Does the except statement not work with SyntaxErrors??
2 Respuestas
+ 4
No. Try except logic is designed to catch runtime errors only.
https://stackoverflow.com/questions/25049498/failed-to-catch-syntax-error-JUMP_LINK__&&__python__&&__JUMP_LINK
+ 2
Here is what I was experimenting with, but it looks like Simon answered my question. Thanks!
try:
print("Hello")
print(1 / 0))
except ZeroDivisionError:
print("Divided by zero")
except SyntaxError:
print('Syntax error!')
finally:
print("This code will run no matter what")