iNTERFACEWARE Products Manual > Learning Center > Learning Python > Error Detection > Overview of Errors |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
In Python, there are two kinds of errors: syntax errors and runtime errors. Syntax errors occur when you write code that Python does not understand. For example:
This example is incorrect because if cannot be used as a variable. If you try to run this program, you will get an error that looks something like this:
When Python detects a syntax error, it tries to make a best guess as to where the problem is located. Runtime errors are trickier, as they cannot be detected until your program is actually running. For example, here is a simple program that generates a runtime error:
This code does not contain any syntax errors, as each statement is perfectly legal Python. But, when you try to run the program, it generates a runtime error when it tries to divide 4000 by 0:
As you can see, the program stops running when the runtime error is detected. This might not be the outcome you want: if your program is processing a large amount of data, you might not want it to halt whenever it detects a runtime error. Instead, you would likely want the program to deal gracefully with the error and continue running. |