What is the point of the SyntaxError
builtin in python? It doesn't seem to have any practical use because SyntaxError
s are found by the python interpreter before the code is run. Example:
try:
&@!5_+ #SyntaxError
except: pass
This fails with a SyntaxError
because the SyntaxError
is found before it can be handled. Now this works and fails silently, like intended:
try:
raise SyntaxError
except: pass
However, I have never seen a function
or class
or anything raise a SyntaxError
. So why does this exist so easy to use and catch when the only use seems to be raising it pointlessly? Is there someplace that python raises a SyntaxError
that it can be caught? Or does it just exits in the builtin scope just to be there?