liveBook · Manning

Failure path

As explained in The Art of Code

A failure path is a sequence of execution possibilities through which an operation encounters an unsuccessful or exceptional outcome.

A failure path is a sequence of execution possibilities through which an operation reaches an unsuccessful or exceptional outcome. Good design identifies these paths before users encounter infinite spinners, raw stack traces, or abandoned workflows. Graceful handling may use domain-specific exceptions or explicit result types, while unexpected programming errors should fail fast. section 7.1.1 section 7.2.2

Make failure paths readable and operationally useful:

  • Catch specific expected failures instead of routing every exception through generic fallback logic. section 7.2.2
  • Keep protected blocks tight enough that readers can see which related operations may fail and what follows. section 7.2.2
  • Separate minor failures from serious signals in logs so monitoring can reveal threats to robustness or security. section 7.2.2
  • Prevent raw stack traces and sensitive implementation details from reaching users. section 7.1.1

Reading a file

A broad catch obscures whether opening, reading, or processing failed. Specific catches make the failure narrative visible: report a missing file with a warning, report read failure as an error, and keep the protected operation compact. section 7.2.2

try (BufferedReader reader = new BufferedReader(
  new FileReader("data.txt"))) {
    String line = reader.readLine();
    processLine(line);
} catch (FileNotFoundException e) {
  logger.warn("DATA_01: File 'data.txt' not found.", e);
} catch (IOException e) {
  logger.error("DATA_02: Failed to read from 'data.txt'.", e);
}

Compare generic exception handling with specific FileNotFoundException and IOException paths, including distinct diagnostic messages. section 7.2.2

How The Art of Code covers it

How deep it goes
Explains identification, catch scope, logging, and user-facing consequences, but stops short of detailed result-type design.
Examples
Uses file opening and reading, unexpected user behavior, infinite spinners, raw stack traces, and specific Java exception catches.
What it assumes
Assumes familiarity with operations, exceptions, method calls, logging, and user-facing application behavior.
What you can do after
Apply via specific exception catches, tight protected blocks, differentiated logging, and explicit failure contracts.
How it connects
Connects exception handling, fallback logic, fail-fast behavior, stack traces, observability, and explicit result types.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.