Quantcast
Viewing latest article 17
Browse Latest Browse All 21

Answer by Baldrickk for Limits of Defensive Programming acknowledging that Exception Handling should be avoided

Are you expecting null data?

Exceptions are intended for exceptional circumstances.

The simple rule of thumb for situations like this is to handle standard cases with logic, not exceptions.
If a NULL is an error, indicating a transmission failure for example, then an exception is suitable.If however, it is indicating that an optional field is empty, then this is a "normal" use-case, and should be checked with logic.

The example used in the question implies that the data in invalid if some data is missing (and that this is unexpected).
I would recommend exceptions in this case.


Viewing latest article 17
Browse Latest Browse All 21

Trending Articles