/ɪkˈspɛkʃən/

noun — "that moment your code says 'nah, not today' and throws a fit."

Exception is a condition in programming that occurs when a program encounters an unexpected situation or error that interrupts normal execution. Exceptions signal that something unusual has happened, such as invalid input, division by zero, or a missing file. Handling exceptions properly allows programs to recover gracefully or fail safely, rather than crashing abruptly.

Technically, Exception involves:

  • Raising or throwing — signaling that an unexpected condition has occurred.
  • Catching — intercepting the exception using constructs like try-catch blocks.
  • Propagation — passing the exception up the call stack if not handled locally.
  • Custom exceptions — creating user-defined exception types for application-specific errors.

Examples of Exception include:

  • Attempting to divide a number by zero in Python or Java.
  • Trying to open a file that does not exist, triggering a file-not-found exception.
  • Accessing a null or uninitialized object reference in Java or C#.

Conceptually, Exception is your program’s way of waving a red flag when reality doesn’t match its assumptions. Proper exception handling ensures programs remain robust, maintain logs, and provide meaningful feedback instead of crashing silently.

In practice, Exception management involves using language-specific mechanisms like try-catch, finally blocks, logging, and sometimes alerting monitoring systems when critical exceptions occur.

See Error, Debugging, Logging, Try-Catch, Runtime.