Back to Coding

What Do You Do When the Code Does Not Run?

What Do You Do When the Code Does Not Run?
AI Tutorials Team 19 February 2026

Code failing to run is not a setback, it is the normal state of code before it works. The error message is the most information-dense thing you will encounter, and learning to read one is worth more than any number of working scripts.

What does an error message contain?

Three things: what went wrong, where it happened, and how it got there. The last line is usually the type of error and a short description. The lines above it are the path through the code that led to the failure.

Beginners read the first line and give up; the useful information is at the bottom.

What are the common first errors?

  • Something not found. A file, a folder or a library that is not where the code expects.
  • A name error. Referring to something that has not been created yet, frequently a typo.
  • A type error. Treating a number as text or the reverse.
  • Indentation problems. Particularly in Python, where spacing is meaningful.
  • Permission denied. Trying to write somewhere the system will not allow.

What should you do first?

Read the last line and the line number. Together those tell you what and where, which is usually enough. Go and look at that line before doing anything else.

How do you ask for help properly?

Here is the code and here is the complete error message, copied exactly. Before fixing it, explain what the error means in plain English and why it happened here. Then tell me what to change and why that change fixes it.

Asking for the explanation before the fix is what makes this a learning exercise rather than a repair service.

Why paste the whole message?

Because the part people trim is usually the part that identifies the cause. A truncated error produces a guessed fix, and a guessed fix that happens to work teaches nothing and may introduce something else.

What if the fix does not work?

Say what changed. A new error is progress, and reporting the new message rather than saying it still does not work gives whoever is helping something to work with.

The same applies to an assistant: pasting the new error is far more productive than asking it to try again.

What about code that runs and produces nothing?

A different and more confusing situation, since there is no message. Adding a line that prints something at each stage shows you where execution actually reaches, which is the oldest debugging technique there is and still the most useful for a beginner.

How long should you struggle before asking?

Fifteen minutes on a single error, and it is worth setting a timer. Below that you are not giving yourself a chance to learn the pattern; above it you are usually stuck on something structural that reading will not resolve.

What about errors that appear only sometimes?

The hardest category and worth recognising early. A script that works on most files and fails on one is telling you something about that file rather than about the code, and the useful question is what makes it different.

Usually it is an empty value, an unusual character, a different format or a missing field. Printing the name of each item as it is processed shows you exactly which one it stopped on, which converts an intermittent mystery into a specific case you can look at. That technique is worth knowing before you need it, because the instinct is to rerun and hope.

What is the reframing worth holding?

Errors are the feedback that makes programming learnable. Almost no other activity tells you precisely where you were wrong within a second of being wrong, and treating each one as information rather than as failure is what separates people who continue from people who conclude they cannot do this.