Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128326 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 16EE81A00BC for ; Thu, 31 Jul 2025 06:41:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753943994; bh=PxoLD396kq+sZH99NxFh7GzFPG+qHEzxyfC/rsQNdGc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UhFeloYLdYBNtVrSmx6GXF36fi8pjX6yV8GT0fG+Zkd8R5PxwpjmkeC7+H1rX3n88 CnMBtWb/AYFBWnhKSrZvlbr6cMJZ3TyQxvkdagF2FJlA+vshmPj1QqliHqcNcj7sUB wgJwH9tENac0iUAdrySu8Sw/XExb9AzUQ/sxiKImHSqU9K/xAAXt17oppZBaXNeH5N H8k3IfOrJY2d/jMVpEMRkIvVW57qO4tVpXCYRb1lyvhH9fCcpQef6pSfatOJWnceDB g0XQKj7+W3JCjIq/+vfdHw9bYSucJ3MuETbr5B0i8XGfexFCvyv+oFvvvIzr1cizCz Mu4+/zcIPhg3w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1FAD21801E4 for ; Thu, 31 Jul 2025 06:39:54 +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.4 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: <91liahim@gmail.com> Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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:39:53 +0000 (UTC) Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e8e2b50f8f1so662487276.0 for ; Wed, 30 Jul 2025 23:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753944095; x=1754548895; 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=6p6NJp8QxqydLTZFpMy6fWOhj4LW8bCsCZe8OeMq3+w=; b=iqSwzj8WErN5GvHcfA4vXcr7KhIQxM65YunDucAhDJSHCjeHEBW6NTqGsZk7x/AJOc pmTmnU1fDwVJWta5OjYVwBNdt1mmbrpzYFoWZ5iLdKitud4G3dm8t1CYDYCUy2jy3gjy /W2ApZUDg4qG3fY5tSIkJluUbPmAUzpFH31wVcDNqdr2NmzXA7tdgjpcfzvbG+/15UN3 4cBEpE4Jw/P32UJOJJ9C1ixHGF3Ts3y7rqGLMx0bd4NZzII49lhyabWYMmZtHRUWEXNN 55pdEOzDFcYsD3vDhLSQMqdPVUS6CRlvI2kDfn6/rVwwlg+KFPLThsWTadEI5++W5Bqe BD9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753944095; x=1754548895; 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=6p6NJp8QxqydLTZFpMy6fWOhj4LW8bCsCZe8OeMq3+w=; b=hLEmdB3UjOun9KOxZHJtV5eZ2S1EPkxmOIQ3miP2DDJu8UAYXOdJ9li0FMEMME8IH9 fyO4sa+akq+Ohujy9iaSC5XCJS7Dy9Q+PYsrXGtC4a0ZCXbfs/AojFxYRgbhggXF6dPP I0IrY0AHqrla4e0Gs4j773wT3jIFp+HBRoyoG781NcAPUm1eF+RdaziSYrDb4Bzr/F/N xhrgQ18S7rnzZydGEUjC0ONdWGEjhG9dBAbjx5hdfK5iryJp0qGvZdR23QaeSDn7Dilt dfiTxdlGuV97CfS3vL/wFfJHMcgvQ4oNP4D+Qqlg6F+K4h9YaqNqrRh38sO8Qea8vX2N KETw== X-Gm-Message-State: AOJu0YxkQhtIDwDkFQhNnRkRlzsXdJVk1fch5QPcfcLGhTPPfDdzjoQl 0boS7Key2+RizdNP/7+xcZVC4rS0Ut4Rikpiak2nAaXw/V85mfwDlK2mpzFcUz7yIFnJmvYqZjE p59x24huScThINlhc/4qlTcPkaYWGVdF3T/iQ X-Gm-Gg: ASbGncuv+DbYI9q0Yjo4SnYm43W8Ei/vV2CS1ryqtPfhnxvVOvMUu2ddG4IIOLvHdGd G8a9Y17e9ptG5lQl4r3sajNZzKf4cUTb4WzgDP87IbL2df2R5M9cUSOOEzWxIWaUx9PR6xkDtG1 pkTzq6I7f4yCvx4dmBhSuHM9KIdIQuNpRJxN4HtabhM/BufjtjhtyXDy1IKyfmB6GjU2DVfeGsD zit0hM= X-Google-Smtp-Source: AGHT+IGOj2ZfFl2fr7yGhizTrEQ2FnSQkGn2/SefhdH030iZ5Vp143uSOU6KT38KOqm84eRUhjBzsrlcEcGV+EQlfGI= X-Received: by 2002:a05:6902:2745:b0:e8d:e898:9c37 with SMTP id 3f1490d57ef6-e8e3151e3d2mr7693704276.31.1753944095238; Wed, 30 Jul 2025 23:41:35 -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 11:41:24 +0500 X-Gm-Features: Ac12FXzfRIkW8NYlm-alIEhM0vyjYC9RJQ3IuABSELdCCfr6woeFUhnJlFCpyeQ Message-ID: Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body To: Dmitry Derepko Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000c0b048063b33ee89" From: 91liahim@gmail.com (Mihail Liahimov) --000000000000c0b048063b33ee89 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Dmitry I've been thinking about all these problems. I can't say a definite decision yet, but I think it will be possible to discuss specific solutions if the community approves this proposal in principle. At the moment, I was thinking about a similar syntaxis.: try { } catch (ErrorA) catch (ErrorB) { // some handling } or with finally: try { } catch (Error) finally { // ... } =D1=87=D1=82, 31 =D0=B8=D1=8E=D0=BB. 2025=E2=80=AF=D0=B3. =D0=B2 11:33, Dmi= try Derepko : > On Thu, Jul 31, 2025 at 7:55=E2=80=AFAM Mihail Liahimov <91liahim@gmail.c= om> > wrote: > >> Introduction >> >> Currently, PHP requires a block body for catch clauses even when the >> caught exception is not used. This results in unnecessary boilerplate co= de. >> This RFC proposes allowing catch clauses without a body when the excepti= on >> 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 > --000000000000c0b048063b33ee89 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, Dmitry

I've been thinking about all these p= roblems. I can't say a definite decision yet, but I think it will be po= ssible to discuss specific solutions if the community approves this proposa= l in principle.

At the moment, I was thinking about a similar syntax= is.:

try {
} catch (ErrorA) catch (ErrorB) {
// some handling<= br>}

or with finally:

try {
} catch (Error) finally {
/= / ...
}

=D1=87=D1=82, 31 =D0=B8=D1=8E=D0=BB. 20= 25=E2=80=AF=D0=B3. =D0=B2 11:33, Dmitry Derepko <xepozzd@gmail.com>:
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 code. This RFC proposes allowing catch clauses = without a body when the exception variable is omitted.

Proposal
<= br>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.=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 // cod= e that may throw
} catch (SomeError)
=C2=A0finally {}

Should the error flow into the "finally&quo= t; construction?=C2=A0


--
Best regards,
=
Dmitri= i Derepko.
--000000000000c0b048063b33ee89--