liveBook · Manning

Exception

As explained in Clean Applications with Hexagonal Architecture

An exception is a Java control-flow mechanism that represents an abnormal condition by transferring execution to exception-handling code.

A command such as `void handle(SomeCommand)` promises no return data, but says nothing about failure. When exceptions are its only failure channel, expected outcomes remain invisible to callers. section 4.0 section 4.2

Reserve exceptions for faults the application cannot reasonably model or recover from, such as programming errors or infrastructure failures. Put expected contingencies in the use-case contract as typed outcomes, such as `Either<Error, R>`. section 4.0 section 4.2.1

Contingencies and faults

A duplicate email, missing article, or rejected authorization is an expected outcome a caller can react to. Corrupted state or an unrecoverable runtime problem may remain exceptional. section 4.2.1

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Distinguishes expected contingencies from faults and explains contract costs, without detailing exception-handling implementation.
Examples
Contrasts duplicate emails and missing articles with programming errors, corrupted state, and infrastructure failures.
What you can do after
Evaluate whether a failure is an expected use-case outcome or an exceptional fault, then choose an explicit contract accordingly.
How it connects
Links exceptions to use-case contracts, checked and unchecked exceptions, and typed Either outcomes.

Also explained in

Compare how 29 books explain exception →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.