Exception::getPrevious

(PHP 5 >= 5.3.0, PHP 7)

Exception::getPrevious锟斤拷锟斤拷锟届常锟斤拷锟叫碉拷前一锟斤拷锟届常

说锟斤拷

final public Exception::getPrevious ( void ) : Throwable

锟斤拷锟斤拷锟届常锟斤拷锟叫碉拷前一锟斤拷锟届常锟斤拷Exception::__construct()锟斤拷锟斤拷锟侥碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

锟剿猴拷锟斤拷没锟叫诧拷锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷锟届常锟斤拷锟叫碉拷前一锟斤拷锟届常 Throwable锟斤拷锟斤拷锟津返伙拷NULL锟斤拷

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
7.0.0 锟斤拷锟斤拷锟斤拷锟酵的讹拷锟斤拷某锟斤拷锟� Throwable锟斤拷

锟斤拷锟斤拷

Example #1 Exception::getPrevious()示锟斤拷

追锟斤拷锟届常锟斤拷锟斤拷循锟斤拷锟斤拷印锟斤拷

<?php
class MyCustomException extends Exception {}

function 
doStuff() {
    try {
        throw new 
InvalidArgumentException("You are doing it wrong!"112);
    } catch(
Exception $e) {
        throw new 
MyCustomException("Something happend"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());
}
?>

锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�

/home/bjori/ex.php:8 Something happend (911) [MyCustomException]
/home/bjori/ex.php:6 You are doing it wrong! (112) [InvalidArgumentException]

锟轿硷拷

  • Throwable::getPrevious()