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();
}