Code Lab BetaBUILD. RUN. DISCOVER.
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FILES / CHAPTER 05 / Learn / LESSON 06
A missing file raises FileNotFoundError. Catch it with try/except:
try: with open("missing.txt", encoding="utf-8") as f: print(f.read()) except FileNotFoundError: print("file not found")
Avoid bare except — catch the specific error. The program continues after the message.
Learn: try/except for missing file.
DECISION STANDBY
›