PHP - uitzondering getPrevious() Methode
Voorbeeld
Informatie krijgen over een eerdere uitzondering:
<?php
try {
try {
throw new Exception("An
error occurred", 1);
} catch(Exception $e1) {
throw new Exception("Another error occurred", 2, $e1);
}
}
catch (Exception $e2) {
echo $previous = $e2->getPrevious();
echo $previous->getMessage();
}
?>
Definitie en gebruik
Als de uitzondering door een andere is geactiveerd, getPrevious()
retourneert de methode de andere uitzondering. Anders wordt null geretourneerd.
Syntaxis
$exception->getPrevious()
Technische details
Winstwaarde: | Retourneert een geheel getal |
---|
Gerelateerde pagina's
Lees meer over Exceptions in ons PHP Exceptions Chapter .
❮ Referentie PHP-uitzondering