try, catch, finally Are All Optional¶
<?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();
?>
The finally clause in a try-catch-finally is actually optional: it can be omitted.
The catch clauses in a try-catch-finally are also optional: they can be omitted.
When the catch and finally clauses are all omitted, the try clause can also be omitted safely.
See Also¶
Try-catch-finally are optional [Try me]
PHP Features¶
Last updated: 14 July 2026