Technical Mid Level

How do you structure error handling in a PHP application? When do you use exceptions versus returning error values?

Quick Tip

Show a clear philosophy: "I use exceptions for truly unexpected failures and result objects for expected business-logic outcomes like validation. This keeps the happy path clean."

What good answers include

Good answers distinguish between exceptional situations (database down, invalid state) that warrant exceptions and expected outcomes (validation failure, not found) that may use result objects or specific return types. Strong candidates discuss custom exception hierarchies, global exception handlers, error logging, and how frameworks handle this. They mention the difference between Error and Exception in PHP 7+ and the Throwable interface.

What interviewers are looking for

Tests code design maturity. Candidates who use exceptions for flow control or silently swallow errors are problematic. Look for a thoughtful, consistent approach.

← All PHP questions