Stop Using Exceptions for Validation: Use the Notification Pattern instead

When you use exceptions during validation for example you trigger a "fail-fast" response. The program stops at the first error it finds and throws the exception.

If a user submits a form with let's say 5 errors, the fail-fast approach results in frustrating experience:

The user fixes one error… submits again… gets another error… repeats 5 times.

Solution? Use the Notification Pattern (popularized by Martin Fowler).

Article content


The benefit of introducing such a class is that you can now declare a validator that is able to collect multiple errors in one pass. Instead of throwing exceptions, you can now simply add messages into the Notification object.

Article content


This approach leads to better user experience and a cleaner easier to maintain flow.

Do you prefer fail-fast or collecting all errors?

To view or add a comment, sign in

More articles by Amine Asli

Explore content categories