PHP › Error & Exception Handling
What is the difference between a PHP error and a PHP exception?
BeginnerAnswer
A PHP error traditionally represents a problem detected by the PHP engine itself, such as calling an undefined function, and historically these were handled differently from exceptions, while an exception is an object representing an exceptional condition that your own code or a library deliberately throws, and can be caught and handled gracefully using a try catch block, with modern PHP versions unifying much of this behavior so that many previously fatal errors are now also represented as catchable Error objects implementing the same Throwable interface as exceptions.
try {
$result = 10 / 0;
} catch (DivisionByZeroError $e) {
echo 'Cannot divide by zero';
}Real-world example A calculation function safely catches a DivisionByZeroError, which in older PHP versions would have been an uncatchable fatal error, allowing the application to display a friendly error message instead of crashing entirely.