try, catch, finally sont tous optionnels
<?php
try {
doSomething();
} catch (Exception $e) {
processException($e);
} finally {
cleanupWork();
}
// finally is optional
try {
doSomething();
} catch (Exception $e) {
processException($e);
}
// catch is optional
try {
doSomething();
}
// In the end, catch is also optional
doSomething();
?>
La clause finally dans un try-catch-finally est en fait optionnelle : elle peut être omise.
Les clauses catch dans un try-catch-finally sont également optionnelles : elles peuvent être omises.
Lorsque les clauses catch et finally sont toutes omises, la clause try peut également être omise en toute sécurité.
See Also
- Try-catch-finally are optional [Try me]
PHP Features
Last updated: 11 October 2026