Programs are written programmers and hence contain many errors. It is the function of its computer to detect and report errors in the source program. The error handling is performed by a program called error handler. Whenever a phase of the compiler discovers an error, it must report the error to the error handler, which issues an appropriate diagnostic message. The various errors encountered by different phases of the compiler can be.
(a) The lyrical analysis phase may detect illegal or unrecognized characters or misspelled tokens.
(b) The parser may detect a syntax error e.g. missing parentheses.
(c) The semantic analyzer may detect a syntactic error e. g. type mismatch. The intermediate code generator may detect an operator with incompatible types.
(d) The code optimizer may detect certain unreachable statements.
(e) The code generator may detect a too large constant to fit in a word of the target machine.
(f) The symbol table may contain multiply declared identifiers with contradictory attributes.