Learning to code can be a frustrating endeavor because you are destined to encounter many red errors along the way. What makes a programmer successful isn’t avoiding errors — no programmer can avoid them. Great programmers understand that errors are part of the process, and they know how to find the solution to each while learning something new from them. In this article, we’ll teach you how to think about errors in your code a little differently.
“Errors are simply unavoidable when you develop a program, yet the final program must be free of errors.”
There are many ways of classifying errors. For example:
- Compile-time errors: Errors found by the compiler. We can further classify compile-time errors based on which language rules they violate, for example:
- Syntax errors
- Type errors
- Link-time errors: Errors found by the linker when it is trying to combine object files into an executable program.
- Run-time errors: Errors found by checks in a running program. We can further classify run-time errors.
- Logic errors: Errors found by the programmer looking for the causes of erroneous results.
As you recall, the programming process looks like:
The errors above occur at these places:
[Image coming soon!]
When you are writing C++ programs, your compiler is your first line of defense against errors. Here are the two types of compile-time errors:
int x = 6 // error: missing ;
Int x = 6; // error: Int is not a type
int x = "hello"; // error: wrong type
If your program has no compile-time errors and no link-time erorrs, it’ll run. This is where the fun really starts.
Once we have removed the initial compiler and liner errors, the program runs. Sometimes, no output is produced or that the output that the program produces is just wrong. This can occur for a number of reasons. Maybe your understanding of the underlying program is flawed; maybe you didn’t write what you though you wrote.