Error handling

How code detects and responds to failures: reaching a safe, defined state, giving users only the information they need, and recording the detail in logs rather than in messages users can see.

Error handling decides what code does when something goes wrong, such as unexpected input or a lost database connection. Done securely, it brings the program to a defined, protected state. A check that cannot complete denies the request, and a half-finished transaction is rolled back. This is the fail secure principle in code. NIST SP 800-53 Rev. 5 control SI-11 asks for error messages that give the information needed to correct the problem without revealing what could be exploited, shown only to the roles that need them; it names stack traces and implementation details as exploitable.

Poor handling leaks information and weakens controls. A raw database error can reveal table names that help shape SQL injection, and different messages for “no such account” and “wrong password” can let an attacker list valid accounts. A catch-all handler that logs and carries on can turn a failed check into an approval. The usual pattern is a generic message for the user and the detail in protected logs (log management). The 2025 OWASP Top 10 gives the area its own category: Mishandling of Exceptional Conditions.

Exam relevance: a scenario in which an application shows stack traces or database errors to users is likely to point to improper error handling. Candidates are expected to favour generic messages, internal logging and a secure failure state.