I have a simple list comprehension with "else 0" incorrectly placed at the end. I put that inside a try
block, so I'm expecting the exception to be caught and the print statement to be executed. However, it's returning SyntaxError: invalid syntax
. Here's the code:
try:
[2 * x for x in [1,2,3] if x > 1 else 0]
except SyntaxError:
print("Why isn't this printed?")
Why isn't the error being caught?