PHP 8.6.0 Beta 1 is available for testing

Error::getPrevious

(PHP 7, PHP 8)

Error::getPreviousDevuelve el objeto Throwable anterior

Descripción

final public function Error::getPrevious(): ? Throwable

Devuelve el objeto Throwable anterior (el tercer parámetro de Error::__construct() ).

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

Devuelve el objeto Throwable anterior si está disponible, o null en caso contrario.

Ejemplos

Ejemplo #1 Ejemplo de Error::getPrevious()

Recorrer e imprimir la traza de errores.

<?php
class MiErrorPersonalizado extends Error {}
function hacerCosas() {
 try {
 throw new TypeError("¡Lo está haciendo mal!", 112);
 } catch(Error $e) {
 throw new MiErrorPersonalizado("Ocurrió algo", 911, $e);
 }
}
try {
 hacerCosas();
} 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());
}
?>

Resultado del ejemplo anterior es similar a:

/home/bjori/ex.php:8 Ocurrió algo (911) [MiErrorPersonalizado]
/home/bjori/ex.php:6 ¡Lo está haciendo mal! (112) [TypeError]

Véase también

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /