Exception __toString 实现还将包括此异常链接到的先前异常的字符串表示,_在_当前异常的字符串表示之前。
例如
<?php
class OuterException extends Exception {}
class MiddleException extends Exception {}
class InnerException extends Exception {}
$excA = new InnerException("inner exception", 0);
$excB = new MiddleException("middle exception", 0, $excA);
$excC = new OuterException("outer exception", 0, $excB);
echo "The exception is:\n$excC";
?>
将打印以下内容
The exception is
InnerException: inner exception in test.php:6
Stack trace
#0 {main}
Next MiddleException: middle exception in test.php:7
Stack trace
#0 {main}
Next OuterException: outer exception in test.php:8
Stack trace
#0 {main}