On Thu, Jul 31, 2025 at 7:55 AM Mihail Liahimov <[email protected]> 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:
>
Hey!
I even tried recently to code it. Looked really good and I thought about
publishing it and creating the RFC.
I have use-cases where I need to try to send a request to a server and
forget about an exception if so:
try { $client->post(...); }
If it fails I'm ok with it.
For sure, there are many pitfalls when you allow users to ignore any
exceptions and errors, but it's up to users, right?
About the proposal:
try {
// code that may throw
} catch (SomeError);
How can I catch AnotherError?
try {
// code that may throw
} catch (SomeError)
catch (AnotherError) { ... }
OR
try {
// code that may throw
} catch (AnotherError) { ... }
catch (SomeError);
What about "finally" construction?
try {
// code that may throw
} catch (SomeError)
finally {}
Should the error flow into the "finally" construction?
--
Best regards,
Dmitrii Derepko.
@xepozz