Edited at

try-catchでパイプを使う

More than 1 year has passed since last update.

try

{
// throw(new \Exception('exception'));
// throw(new \Error('error'));
}
catch (\Throwable $error)
{
var_dump($error->getMessage());
}

で事足りるが、ExceptionとErrorだけに絞りたい場合にはパイプが使える

try

{
// throw(new \Exception('exception'));
// throw(new \Error('error'));
}
catch (\Exception | \Error $error)
{
var_dump($error->getMessage());
}