
Programming to Exceptions, Part 1: Method Contracts and Failure
Action methods do their work or throw; query methods return what they promise or don't return. Failures propagate to one catch at the entry point, and each door validates incoming data.

PWI pillar
Failure as a designed path rather than an afterthought. Validation at boundaries, and what catching an exception obliges you to do.
Read Parts 1, 2, and 3 in order: method contracts, exception design, then logging and progress. The concepts apply across languages; the worked examples use C#.

Action methods do their work or throw; query methods return what they promise or don't return. Failures propagate to one catch at the entry point, and each door validates incoming data.

One log record should explain a failure to the support team. Exceptions carry a message, reason, action and context, are translated where meaning is known, and are logged once.

Each failure is logged once at the entry point, with its facts as Application Insights custom dimensions for KQL queries and alerts. A shared progress logger reports long-running work.
Related guidance: Method Design and Gateway Design.