Errors and Debugging – AS Computing Revision (F452)

Types of Error

English: Microsoft Pascal compiler (1988)

English: Microsoft Pascal compiler (1988) (Photo credit: Wikipedia)


  • Syntax errors are errors caused where you’ve broken the rules of the language
  • Runtime errors are where the program has come across an impossible situation during execution
  • Logic errors are where the program works perfectly… but doesn’t do what you wanted
  • (Syntax errors are also known as compilation errors, and runtime errors are also known as execution errors)

Possible Causes

  • Syntax errors include violating the rules for identifiers, not closing a bracket, not ending a construct, trying to assign a string to an integer, sticking a random symbol in for no reason, etc…
  • Syntax errors are immediately obvious to the compiler – it knows it’s an error as soon as it tries to compile it, because it realizes it just won’t work
  • Runtime errors aren’t foreseen by the compiler, often because it doesn’t know what value something will have when the time comes to perform an operation (it could end up dividing by zero, for example, because the user input zero forĀ a laugh)
  • Other than dividing by zero, runtime errors include trying to write to a read-only file or running out of memory – the program is forced to just stop… give up
  • Logic errors are caused by the programmer being stupid not understanding the program well enough
  • The programmer may have started programming before they’d done a proper analysis and design (so, rushing ahead before they knew what they were doing), resulting in logic errors (“I think it ought to work, but it doesn’t. I must have done something wrong… but what?!”)
  • Sometimes logic errors can be caused by a momentary lapse in concentration, such as accidentally forgetting a statement, or putting a statement inside a loop where it ought to be just outside, using OR where you should have used AND, using > instead of >= and so on…

How To Find

  • Syntax errors are quite kindly pointed out to you by translator diagnostics (although you probably don’t think of it as kind, when your program won’t compile!)
  • Many IDEs (Integrated Development Environments) have a real-time form of translator diagnostics which highlights syntax errors as you type
  • Runtime errors tend to turn up in error messages / debug reports, when your program crashes
  • Logic errors are the hardest to find, because they’re the result of not understanding the program
  • Fortunately, many debugging methods exist to help you find your logic errors…

Debugging Tools

  • Translator diagnostics, as mentioned above, are one way of finding errors, but they only find syntax errors
  • Break points – getting the program to stop when it reaches a certain line (sometimes you’ll set one of these up just to see whether it actually does reach that line! It might skip things because you messed up the condition of an IF statement, or something…)
  • Watches – the program stops automatically once a condition you’ve specified is true (the equivalent of saying to the computer “Run the program, but as soon as <this> happens, stop it so I can have a look!”)
  • Stepping – going through your program line by line, constantly checking up on it to see just where it deviates from what you intended it to do
  • (After each step/break point/watch, you can examine the contents of the variables to see what’s what at that moment)
  • Variable ChecksĀ / Variable Dumps are reports listing how the values of the variables have changed throughout the execution – detailed examination can show you where it went wrong
  • Sticking in some print statements! Whilst it’s not a debugging tool, the output feature will let you make your program say things like “I’ve reached the loop” and “Counter is currently at 17”, so you can see what it’s doing, exactly

About Matt

I like writing, filmmaking, programming and gaming, and prefer creating media to consuming it. On the topic of consumption, I'm also a big fan of eating.
This entry was posted in AS Computing Revision, Revision and tagged , , , , , , , , , , , , . Bookmark the permalink.

Enter comment:

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s