FileNotFoundError

Built-in ExceptionPython 2.0+Beginner

Raised when trying to open a file that doesn't exist

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
# Triggering and catching FileNotFoundError
try:
    open("nonexistent_file.txt")
except FileNotFoundError as e:
    print(f"Caught FileNotFoundError: {e}")
    print(f"Type: {type(e).__name__}")

FileNotFoundError is raised when raised when trying to open a file that doesn't exist. Always catch specific exceptions rather than bare except clauses.

Try in Playground

Tags

exceptionerror-handlingcore