Exception::getPrevious

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Exception::getPreviousÖnceki Throwable nesnesini döndürür

Açıklama

finalpublicException::getPrevious(): ?Throwable

Exception::__construct() kurucusunun üçüncü bağımsız değişkenine aktarılmış olan Throwable nesnesini döndürür.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

Mümkünse önceki Throwable nesnesi, yoksa null döner.

Örnekler

Örnek 1 - Exception::getPrevious() örneği

Döngüsel olarak ve çıktılıyarak istisna izleme.

<?php
class MyCustomException extends Exception {}

function
doStuff() {
try {
throw new
InvalidArgumentException("Yanlış yapıyorsunuz!", 112);
} catch(
Exception $e) {
throw new
MyCustomException("Bir şeyler oldu", 911, $e);
}
}


try {
doStuff();
} catch(
Exception $e) {
do {
printf("%s:%d %s (%d) [%s]\n", $e->getFile(), $e->getLine(),
$e->getMessage(), $e->getCode(), get_class($e));
} while(
$e = $e->getPrevious());
}
?>

Yukarıdaki örnek şuna benzer bir çıktı üretir:

/home/bjori/ex.php:8 Bir şeyler oldu (911) [MyCustomException] /home/bjori/ex.php:6 Yanlış yapıyorsunuz! (112) [InvalidArgumentException]

Ayrıca Bakınız

To Top