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";
?>
將會印出以下內容
例外為
InnerException: inner exception in test.php:6
堆疊追蹤
#0 {main}
Next MiddleException: middle exception in test.php:7
堆疊追蹤
#0 {main}
Next OuterException: outer exception in test.php:8
堆疊追蹤
#0 {main}