PHP 8 · Web, security and database

Handle exceptions

Catch specific exceptions and always run cleanup in finally.

try {
    $result = riskyOperation();
} catch (InvalidArgumentException $e) {
    error_log($e->getMessage());
} finally {
    cleanup();
}

Official PHP 8 documentation

More web, security and database commands

All web, security and database commands · PHP 8 cheatsheet

Was this page helpful?