Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

guard clause

A check at the top of a method that throws if an argument is bad.

A guard clause validates a precondition on entry and throws (for example ArgumentNullException.ThrowIfNull) before any work is done.

Examples

  • if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(quantity)); at the top of a method refuses bad input before any work starts.

Read the full section →