CoursePython from Scratch to Intermediate · Module 8: Errors, Files and Debugging · part 53 of 75
Part 53 · Module 8: Errors, Files and Debugging

Lesson 1: Errors and exceptions, reading them and catching them

15 min read·14 Oct 2026
Module 8 · Lesson 1 · About 50 minutes · Needs: Modules 1 to 7 (loops, dictionaries, functions, datetime dates)

The situation

Amira wants the real files loaded: forty loans, a line each. "If one line is wrong, tell me which one. Don't just stop." Until now, one bad value has stopped your whole cell. With forty lines, and Tom's notebook to come, that will not do.

This lesson follows one line from loans.csv, Ben's loan L13: L13,B20,M02,2026-09-21,. Read correctly, it gives a borrow date of 21 September, 9 days late today, 180 pence owed. Typed the way Tom types dates, 21/09/2026, it stops the program. You will learn to read that stop, catch it, and raise your own.

BEN, LOAN L13, THE WAR OF THE WORLDS 2026-09-21 read_loan 21 Sept a real date 9 days days_late 180p late_fee THE SAME LOAN, TOM'S DATE 21/09/2026 read_loan ValueError: stops here nothing after it runs
Ben's line becomes a date, 9 days late and 180p (blue is your code, green the answer); the same loan with Tom's date stops at the first step with an error (red).

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.