To avoid errors or handle them, you need to understand what they are and what causes them. Errors in programming can be classified into three main categories:
Syntax errors
Runtime errors
Logic errors
Most of the errors that you will need to handle are in the middle category (runtime errors); however, the other two categories are equally important.
Syntax errors, also known as compiler errors, occur commonly when you mistype some part of a language or use it incorrectly. The most common causes of such errors are missing semicolons, brackets or parentheses, mistyped language statements, and so on.
They are easy to spot; code containing such errors won't compile (if the language is compiled, such as C++ or Java) or won't run (in the case of interpreted languages, such as PHP, Python, or Ruby). The compiler or interpreter will issue the error and terminate an execution as soon as it parses the file.