FileExistsError
Built-in ExceptionPython 2.0+Intermediate
Raised when trying to create a file that already exists
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
Learn by Difficulty
Quick Example
python
# Triggering and catching FileExistsError try: raise FileExistsError("example error") except FileExistsError as e: print(f"Caught FileExistsError: {e}") print(f"Type: {type(e).__name__}")
FileExistsError is raised when raised when trying to create a file that already exists. Always catch specific exceptions rather than bare except clauses.
Try in PlaygroundTags
exceptionerror-handlingcore