PHP schließlich Schlüsselwort
Beispiel
Führen Sie Code unabhängig davon aus, ob eine Ausnahme ausgelöst wurde:
<?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";
}
?>
Definition und Verwendung
Das finally
Schlüsselwort wird in try...finally
und try...catch...finally
-Strukturen verwendet, um einen Codeblock auszuführen, unabhängig davon, ob eine Ausnahme aufgetreten ist oder nicht.
Verwandte Seiten
Das throw
Schlüsselwort.
Das catch
Schlüsselwort.
Das finally
Schlüsselwort.
Lesen Sie mehr über Ausnahmen in unserem PHP-Ausnahmen-Tutorial .
❮ PHP-Schlüsselwörter