Ausgabeschleife über einen Exception-Verlauf
    
<?php
class MyCustomException extends Exception {}
function doStuff() {
    try {
        throw new InvalidArgumentException("Sie machen es nicht richtig!", 112);
    } catch(Exception $e) {
        throw new MyCustomException("Irgendetwas geschah", 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());
}
?>
     
    Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:
/home/bjori/ex.php:8 Irgendetwas geschah (911) [MyCustomException]
/home/bjori/ex.php:6 Sie machen es nicht richtig! (112) [InvalidArgumentException]