Sunday, October 10, 2021

PHP try catch

In case you haven't found out yet, PHP 7 and PHP 5 catch the exception differently. Throwable vs Exception.

In PHP 7. 

try {
    throw new Error('foobar');
} catch (Throwable $e) {
    echo $e->getMessage();
}

In PHP 5. 

try {
    throw new Error('foobar');
} catch (Exception $e) {
    echo $e->getMessage();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.