Built-in Exceptions
SyntaxError — exception class
Signals invalid Python source detected by parsing or compilation. The interpreter cannot execute a module containing invalid syntax; catch the error around compile() of separate source text. Inspect lineno, offset and text when available. Catch SyntaxError when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
SyntaxErrorReturn Value
type
The class object SyntaxError; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
try: compile("if True print(1)", "<demo>", "exec")except SyntaxError as error: print(type(error).__name__)