The answer lies in the previousclass property Exception. To get the original exception, the block try - catchshould be slightly modified:
try {
json_encode(new MyClass);
} catch (Exception $e) {
if ($e->getPrevious()) {
print $e->getPrevious()->getMessage() . "\n";
} else {
print $e->getMessage() . "\n";
}
}
This exception can also be re-selected:
try {
json_encode(new MyClass);
} catch (Exception $e) {
if ($e->getPrevious()) {
throw $e->getPrevious();
} else {
throw $e;
}
}
source
share