(PHP 5 >= 5.3.0, PHP 7)
Exception::getPrevious — �����쳣���е�ǰһ���쳣
�����쳣���е�ǰһ���쳣��Exception::__construct()�����ĵ�������������
�˺���û�в�����
�����쳣���е�ǰһ���쳣 Throwable������NULL
��
�汾 | ˵�� |
---|---|
7.0.0 | �������͵Ķ���ij��� 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]