P-1.5 How Programs Fail, and How to Read That
You can tell a compile error, a crash and a wrong answer apart, read a stack trace to the line that matters, and narrow a fault by forming and testing one hypothesis at a time.
Debugging is taught by osmosis almost everywhere, which is why so many people do it by changing things until the symptom moves. It is an ordinary skill with an ordinary method: decide which of three kinds of failure you have, read what the machine actually said, form one hypothesis, and test it. The habit to unlearn is reading the first line of an error and stopping, because the line that names your own code is usually further down.
Work through these
Three kinds of failure: it would not build, it stopped, it gave the wrong answer
The three have completely different causes and completely different methods, so naming which one you are looking at is the first move. The third is the dangerous one, because nothing announces it.
Read an error message to the end, then find the line that is yours
A stack trace reads from the point of failure outward through everything that called it, and the frame that matters is usually the deepest one inside code you wrote. Skipping to the top line is how people conclude the library is broken.
Reproduce it before you fix it, and make the reproduction small
A fault you cannot make happen on demand cannot be confirmed fixed, and cutting the case down until nothing can be removed usually identifies the cause on its own.
One hypothesis at a time, and change one thing to test it
Changing three things and seeing the symptom go away leaves you not knowing which mattered, and often having added a second defect. Write down what you expect before each run.
Printing values against stepping through with a debugger
Printing is fast, honest and always available; a debugger lets you stop the program and look at everything at once. Both are worth having, and knowing which suits the fault in front of you saves hours.
CS50x: Introduction to Computer Science · Course
Sign in to keep your progress.
Free resources
We haven't checked most of these for screen reader use yet.
Links last checked 31 Aug 2026.
Stuck here?
Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.
Checking your session…
Topics shown in module order.