Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128324 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 2B0651A00BC for ; Thu, 31 Jul 2025 06:33:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753943516; bh=dMaVzUCXkTDawX4Y3d5woVVR0c9BwkRebQCp+fC0aRs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PWXi2um/3QUNEYnvHAGJkm06hzGIqDlGXVVIFNeQqT+Km3ZWF0aF6B0nedjrA2wZQ 7wNoEL5Cz7cxjb7w4ONOSGakhmEkqjjpoN9JKAOX7kr13n4rkLXBA3LxoShnZi+IuO SDzt9iM1jiELMU3l4ZPz13WnWu/JPZmWNw02yJscp2KZLitDmVBTclth8eWMhJdbSZ fBQAT7JQgmzf3b9TAJPSM0SrSjMti2PDfVeuZJ1fwWANbif0A//+tCxUHBGNJ40Ejv bKs+VCyGfw1PR0Deu7zjJdQD4NWtwltHrz36IA98SjavStwdreCa7T2G6mDr2j5mbE vdbjjLEfXO/PA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D602180059 for ; Thu, 31 Jul 2025 06:31:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 31 Jul 2025 06:31:55 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-24041a39005so4508755ad.2 for ; Wed, 30 Jul 2025 23:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753943617; x=1754548417; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YlcZyN7o9NNMGdpO7x3Pp98LBmBkKOHIOo9mCnJtXn0=; b=Qc+xmVV0mZAPKvXoHUe9cZ3DU5OAJCt63zZs7ZM9/1/2+SljoMkMLdrS5qok4ooT6x jzdByCJsrpZVM/EyWtW3ZeVMokVWwrgh1O9/mV1h2mFPgcbBWcZPXZJU7tp5VleMOF6A ioYD8OAMAuGmz8MvV5MG5lNIWcbozFwpD7CbLDFWLwfbhTZQSOrJxSFerLIW1fuVoADR I1FEtktTEwGRF2iSnrk+l518MID0Z522AOT1/1VO8+V/bt/rfspNXI+HnDOM9vsfqwLA Ujui33WSjGQUCO7m/HxZLOTBsWFdJhGg52VKu68md5ZBuhE3pW6e0OSHRrKBsFYIU+3x RTZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753943617; x=1754548417; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YlcZyN7o9NNMGdpO7x3Pp98LBmBkKOHIOo9mCnJtXn0=; b=wKj9tk3bLvzeUOSG9Ajwnkp62Hk/5W/qoJySMOhRok0KhfCBzCxl+ZH9/tJCurZQsK BXp4dw4IWy+dYdKZY4tPIJY0I2hbraxMRvWLIDd8h7QHQyUvYHNfA2fyzOIy/fbbMf53 efQ6aSO250YHl3rqwt6Lp0ETTk8zJeCv00bup2vGZTSvBr6idR0fFtaFy85kOkZ8HBk5 +S0gEz9lDgnMmcU09IF9Fax3jm3kqtxT8tBUz+q/0SjhoAQoHBDfK8Ob/efb7Rl0IQky uZmz7sd7Sp6X1+J3XLbS4LaTUzyFiwXzhKtAI3cBmOtrOtL3LRi/u2i3iDbLRxdf44A2 DnpQ== X-Gm-Message-State: AOJu0YySfMstVeieKI1yWaiwMsJL9f090ye24i0vd4B9r8M2KebIjR9N triBt9mZVqZPI7akOJ0s4yXmKfu6SLfJYLW2MBtvWeA4P++LwPB/DaqMVBxSqo9wEyzBcq3+fjo 1nrqXh0XXXV8E0XEgYJ6pBi/bqpGYEs9xgpj5qw8= X-Gm-Gg: ASbGncvqqoQKz6jrPZFyRv8KyNVHWJ3u+QIx6NUyeNJjw/gypXb/fVe4mE95cTRoKR8 LZxY0o/5E7Sf0SCQwimqz1jDLaFpBjXA0pkieCuIUAO+bt+Hj8lPTnfBXvL5rIXw+2Rruzaucfb aZEH48HR1+iyQEOD9NQNf4LN2BMKrj0qNCq2BE22RppGh3n19rq7JLhOhtUE4sBNU8zzxA1fdaH NFUX5Re X-Google-Smtp-Source: AGHT+IHywsGL9znpYADAQy721ndZMEQ7BbCWV/ATkcdtqFicmgbRAmVH8C3sQXEyM85NndmXf0m7vLcJupVuF7GSotk= X-Received: by 2002:a17:903:46c8:b0:240:7247:f738 with SMTP id d9443c01a7336-24096ac5636mr94048195ad.1.1753943616648; Wed, 30 Jul 2025 23:33:36 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 31 Jul 2025 09:33:24 +0300 X-Gm-Features: Ac12FXw94um_90L2OSSMLVHB4-ov6XqiAb9CdKCskmwg7XRU2Zf4ECsFOfKkx58 Message-ID: Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body To: Mihail Liahimov <91liahim@gmail.com> Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000039fa11063b33d2a6" From: xepozzd@gmail.com (Dmitry Derepko) --00000000000039fa11063b33d2a6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jul 31, 2025 at 7:55=E2=80=AFAM 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 cod= e. > This RFC proposes allowing catch clauses without a body when the exceptio= n > 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? --=20 Best regards, Dmitrii Derepko. @xepozz --00000000000039fa11063b33d2a6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Jul 31, 2025 at 7:55=E2=80= =AFAM Mihail Liahimov <91liahim@gm= ail.com> wrote:
= Introduction

Currently, PHP requires a block body for catch clauses = even when the caught exception is not used. This results in unnecessary boi= lerplate code. This RFC proposes allowing catch clauses without a body when= the exception variable is omitted.

Proposal

Allow the follow= ing 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.=C2=A0

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 except= ions and errors, but it's up to users, right?

= About the proposal:

try {
=C2=A0 =C2=A0 // code= that may throw
} catch (SomeError);

How ca= n I catch AnotherError?

try {
=C2=A0 =C2=A0 // = code that may throw
} catch (SomeError)
=C2=A0 catch (AnotherE= rror) { ... }

OR

try {=C2=A0 =C2=A0 // code that may throw
} catch (AnotherError) { ... }
=C2=A0catch (SomeError);

What about "f= inally" construction?

try {
=C2=A0 =C2=A0 // code that may throw
} catch (Some= Error)
=C2=A0finally {}

Should= the error flow into the "finally" construction?=C2=A0
=

-- <= br>
Best regards,
Dmitrii Derepko.
--00000000000039fa11063b33d2a6--