Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Catch On Interfaces

<?php

interface i {}

class x extends \Exception implements i {}

try {
    throw new x();
} catch (i $x) {
    print "Caught!";
}

Exceptions can be caught using their interfaces rather than their specific class names or parent classes. This introduces polymorphism to exception handling, allowing the same exception to be caught in multiple ways. By targeting interfaces, developers gain flexibility in managing errors, especially when different exception types share common behavior defined by a shared interface.

See Also

PHP Features

Last updated: 09 November 2026