[RFC] Optional Catch Block Body
| From: | Mihail Liahimov | Date: | Thu, 31 Jul 2025 04:53:25 +0000 |
| Subject: | [RFC] Optional Catch Block Body | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-128320@lists.php.net to get a copy of this message | ||
Introduction
Currently, PHP requires a block body for catch clauses even when the caught
exception is not used. This results in unnecessary boilerplate code. This
RFC proposes allowing catch clauses without a body when the exception
variable is omitted.
Proposal
Allow the following syntax where the curly braces can be omitted when no
exception variable is specified and no handling is needed:
try {
// code that may throw
} catch (SomeError);
This would be equivalent to:
try {
// code that may throw
} catch (SomeError) {}
Motivation
Reduced Boilerplate: Eliminates unnecessary empty blocks when exceptions
only need to be caught and ignored.
Improved Readability: Makes the code more concise and focuses on the
important parts.
Backward Incompatible Changes
None. This is purely an additive change to the syntax.