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 est optionnel

<?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();
}

?>

Dans une commande Try Catch Finally, seule la partie try est obligatoire. Il est possible de créer une commande try sans aucune clause catch : de cette façon, les exceptions ne sont effectivement pas capturées. La clause finally est également optionnelle, mais lorsqu’elle est fournie, elle est toujours exécutée, même si les exceptions ne sont pas capturées.

See Also

PHP Features

Last updated: 11 October 2026