PHP vang Sleutelwoord
Voorbeeld
Vang 'n uitsondering:
<?php
try {
throw new Exception("This is an exception");
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
Definisie en gebruik
Die sleutelwoord word gebruik om uitsonderings te hanteer wat deur die kode in 'n vorige probeerblokcatch
gegooi word .
Verwante bladsye
Die throw
sleutelwoord.
Die try
sleutelwoord.
Die finally
sleutelwoord.
Lees meer oor try..catch.finally (Uitsonderings) in ons PHP -uitsonderingstutoriaal .
Meer voorbeelde
Voorbeeld
Gebruik catch vir veelvuldige tipes uitsonderings:
<?php
try {
$rand = rand(0, 2);
switch($rand) {
case 0: throw new Exception();
case 1: throw new
OutOfBoundsException();
case 2: throw new
LogicException();
}
} catch(OutOfBoundsException $e) {
echo "Caught an out of bounds exception";
} catch(LogicException $e) {
echo "Caught a logic exception";
} catch(Exception $e) {
echo
"Caught an ordinary exception";
}
?>
❮ PHP sleutelwoorde