EMZETT.
Login

Errors

In short: An umbrella term for everything that can go wrong while writing or running a program — from syntax errors that the compiler directly rejects, to runtime errors that only occur during execution.

In more detail: A rough distinction is made between syntax errors (code violates the grammar of the language, doesn’t compile at all), logic errors (the code runs, but doesn’t do what’s intended), and runtime errors or exceptions (a concrete problem during execution, e.g. division by zero). Debugging is the process of systematically finding and fixing such errors.

In Depth

The three types of error differ mainly in WHEN and HOW clearly they become noticeable:

Syntax errors violate the grammar rules of the language itself — a missing parenthesis, a forgotten semicolon. The compiler or interpreter detects this already while translating and doesn’t even let the program start. This is the most harmless type of error, since it’s noticed immediately and unmistakably, usually already in the IDE, before you even run the program.

Runtime errors (see Exceptions) only occur during execution, when a specific, initially syntactically correct operation fails — a division by zero, access to a non-existent array index, a file that isn’t found. The code itself is grammatically correct, but fails on a specific situation at runtime.

Logic errors are the trickiest: the program runs with no error message at all, but produces a wrong result — e.g. a comparison condition written the wrong way round (> instead of <) or a calculation with a wrong formula. Because no error is thrown, logic errors are often only noticed when a result is obviously implausible, or not at all — which makes them especially dangerous and is the main reason tests (which check expected against actual results) matter so much.

// Syntax error: missing closing parenthesis -> doesn't compile
if (condition {
    doSomething()
}
 
// Runtime error: runs, but fails for certain inputs
result = 10 / input    // crashes if input == 0
 
// Logic error: runs error-free, but the result is wrong
if (age > 18):          // should be >=, 18-year-olds are wrongly excluded
    allowAccess()

The order in which these error types are typically worked through also mirrors their visibility: syntax errors first (the code doesn’t even compile), then runtime errors (the program crashes at a specific spot), and last logic errors (the program runs, the result is just wrong) — debugging gets more demanding at each stage, because fewer direct clues about the cause of the error are available.

See also: Exceptions, Debugging, Error Codes