SyntaxWarning
Built-in ExceptionPython 2.0+Intermediate
Warning about suspicious syntax
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
# Triggering and catching SyntaxWarning try: import warnings; warnings.warn("syntax issue", SyntaxWarning) except SyntaxWarning as e: print(f"Caught SyntaxWarning: {e}") print(f"Type: {type(e).__name__}")
SyntaxWarning is raised when warning about suspicious syntax. Always catch specific exceptions rather than bare except clauses.
Try in PlaygroundTags
exceptionerror-handlingcore