demis dot palma at tiscali dot it ¶
6 years ago
Throwable does not work on PHP 5.x.
To catch both exceptions and errors in PHP 5.x and 7, add a catch block for Exception AFTER catching Throwable first.
Once PHP 5.x support is no longer needed, the block catching Exception can be removed.
try
{
// Code that may throw an Exception or Error.
}
catch [Throwable $t]
{
// Executed only in PHP 7, will not match in PHP 5
}
catch [Exception $e]
{
// Executed only in PHP 5, will not be reached in PHP 7
}
lubaev dot ka at gmail dot com ¶
5 years ago
php 7.1
try {
// Code that may throw an Exception or ArithmeticError.
} catch [ArithmeticError | Exception $e] {
// pass
}
diogoca at gmail dot com ¶
2 years ago