PHP enfin mot-clé
Exemple
Exécutez du code, qu'une exception ait été levée ou non :
<?php
echo "Starting the process.";
try {
// Select
randomly between 0 and 1, throw an exception if 1 is selected.
$random = rand(0, 1);
if($random == 1) {
throw
new Exception("Exception");
}
} finally {
echo "Process
complete";
}
?>
Définition et utilisation
Le finally
mot-clé est utilisé dans les structures try...finally
et try...catch...finally
pour exécuter un bloc de code, qu'une exception se soit produite ou non.
Pages connexes
Le throw
mot clé.
Le catch
mot clé.
Le finally
mot clé.
En savoir plus sur les exceptions dans notre tutoriel sur les exceptions PHP .
❮ Mots clés PHP