- print_r: documentation ( source)
<?php
function functionCall4()
{
if (true or mt_rand(1, 4) === 2) {
throw new \Exception('exception');
}
}
function functionCall3()
{
functionCall4();
}
function functionCall2()
{
functionCall3();
}
function functionCall1()
{
try {
functionCall2();
} catch (\Exception $e) {
throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
}
}
try {
functionCall1();
} catch (\RuntimeException $e) {
echo 'Exception caught', PHP_EOL;
while ($e) {
echo 'Trace for ', get_class($e), "\n";
print_r($e->getTrace());
$e = $e->getPrevious();
}
}