(PHP 7, PHP 8)
Error::getPrevious — Gibt das vorherige Throwable zurück
Gibt das vorherige Throwable zurück (das dritte Argument von Error::__construct()).
Diese Funktion besitzt keine Parameter.
Beispiel #1 Error::getPrevious()-Beispiel
Schleife über und Ausgabe von Fehlern
<?php
class MyCustomError extends Error {}
function doStuff() {
    try {
        throw new InvalidArgumentError("Du machst das falsch!", 112);
    } catch(Error $e) {
        throw new MyCustomError("Etwas ist passiert", 911, $e);
    }
}
try {
    doStuff();
} catch(Error $e) {
    do {
        printf("%s:%d %s (%d) [%s]\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode(), get_class($e));
    } while($e = $e->getPrevious());
}
?>Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
/home/bjori/ex.php:8 Etwas ist passiert (911) [MyCustomError] /home/bjori/ex.php:6 Du machst das falsch! (112) [InvalidArgumentError]
