Re: [RFC] Optional Catch Block Body
| From: | Mihail Liahimov | Date: | Thu, 31 Jul 2025 06:15:31 +0000 |
| Subject: | Re: [RFC] Optional Catch Block Body | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128322@lists.php.net to get a copy of this message | ||
Hi, Nick!
It still would be required because we're catching this concrete exception.
Not catching all of throwables.
чт, 31 июл. 2025 г. в 10:43, Nick <php@nicksdot.dev>:
>
>
> On 31. Jul 2025, at 11:53, Mihail Liahimov <91liahim@gmail.com> wrote:
>
> 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.
>
>
> Hey Mihail,
>
> Why would the
catch (SomeError) still be required if it isn’t
> used?
>
> *Cheers,*
> Nick
>