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 Is Optional

<?php

try {
    $x = initSomething();
    doSomething();        // may throw an exception
}

// no catch: exception keep their way

// finally is always executed
// with or without exception being caught
finally{
    $x->shutdown();
}

?>

In a Try Catch Finally command, only the try part is compulsory. It is possible to create a try command without any catch clause: that way, exceptions are indeed not caught. The finally clause is also optional, but when it is provided, it is always executed, even if exceptions are not caught.

See Also

PHP Features

Last updated: 10 September 2026