PHP finalmente palavra- chave
Exemplo
Execute algum código independentemente de uma exceção ter sido lançada:
<?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";
}
?>
Definição e uso
A finally
palavra-chave é usada em estruturas try...finally
e try...catch...finally
para executar um bloco de código, independentemente de ocorrer ou não uma exceção.
Páginas relacionadas
A palavra- throw
chave.
A palavra- catch
chave.
A palavra- finally
chave.
Leia mais sobre exceções em nosso Tutorial de Exceções do PHP .
❮ Palavras-chave PHP