Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128322 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 E2CD51A00BC for ; Thu, 31 Jul 2025 06:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753942442; bh=Ci9CudYD6U/csIwF2QMX9g5cbhVtHkWyn0qNnassT0M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=igDcSpiqrZmvPqtk5nFFNIfiACJjsp0v8u/lyL7pLASBwgIYCqGafs+x7okFM1Md4 edRDRtPm71N3DcBaIFwbWSwBaO4w431ypvAAXySOmqk1986laJQzkVuGnpjMH8vAxW ys5V3L8VegthjTvAfGMKjaNoni5qoRA97APskoerXtn6a0X1YbxeOaskKB29TjZUmV KzdeNL6PwpLtdiRJiKQPGl9HwmCKUxWmTqGajD3Ry3XG9b4UQeKsXXD0AtpVP4PL3l HqhKxxbgA/lY4d+7AFcZSgoAWla3QPejeOyyL+2Vnqbq3vf+BnRG8IjlvWpBQ/S4mu 7DYICNPHmXWqQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B718A180039 for ; Thu, 31 Jul 2025 06:14:01 +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=-1.7 required=5.0 tests=BAYES_05,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-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.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:14:01 +0000 (UTC) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-71b52d6d1e3so5629237b3.1 for ; Wed, 30 Jul 2025 23:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753942543; x=1754547343; 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=deCYcqqjj7h0ndA0cctrnADyQLIsrPKVi9WK+/wN72w=; b=RiidGeYC2NvYE02OsPTZSZxVue3CbTGj4iQ8UjL7oqVcEIGu4kWGgFkpCom3KMAzLw IBrIybeln6SOHVQEviIwsL5zjz6wOIWbuA086agy9rElKMVm9p3ntgA2NyoI4Q0/qDZI 8xiYXTzrl7Q412o9tk+LX8gy96ErYVxeRnt4OfPNnOliLfF9IsbHClfZn9K+03bJq7X2 hLG3Pw6TGUa4NL6CtXH9HGSG4mxBvABAcLGjwfVNlcWEjzw3z0HVjojKB8r4W0h3hIyq MBWDqEMVJ69sqzKfqivKsZ8ehYJ3/DDCWspxpvwEIY/ZGV+cKpWA3UjsSzstJ1qVyfGc mvng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753942543; x=1754547343; 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=deCYcqqjj7h0ndA0cctrnADyQLIsrPKVi9WK+/wN72w=; b=lkVu11i/+QhxAzcJ6f2Gwtb3yidhYrON5rHpP2WLQVGXpGlwZ+X8jzNGIzlrChuxxp 0iF2fMNCzKLPu4qWD1oLoSw0DwBL1VdGbO4LrxzF15VbRUGuuCi/B0RgvucA4VyTDt3K 90KoCaIpodZxt4A/kNbocCkHRjePRjJOTjqjBCBD6cALV5eHc54sS31k6+txzGDqGhU7 uTqzBLxk1NFvCuqoc1sW9ynCDl0yT8/yWlao1ITzvMWe3+cmlbNnPS8SCOrs3GGH1I2p chKtgcglXZifw0RrayWdOI1eklx272FLP66jHkJnQnmq4Oll0RaZ09sBT04ItQgwDOig wZEQ== X-Gm-Message-State: AOJu0YyGeV5zXWHXAEr3zR6nEpylMP4Ybh+XpdODy3zRDFXXbnVW278I UMcM7TgYPxSBXsLW8XKe/il5dArYbEWmNrgnUvzGItcxDxAZ2Q92BGC2UUFU+rolVceEkVetNB5 OWChchph7QVMQTVi++83gLyj5S1KN3XRkHA== X-Gm-Gg: ASbGncsZBqJ4DGAVjzDlywbJ4CJstDUsswnLSZ2EqXxfuyWK2oDeFnSIp4nusidkfhW GxNH4S5inHlTfLbGXNb7EFDKIIQwTg1IHg82tArHwG98iJoWBjvbM5CZZht1CNGHJwOyv1RKY9T d5TnkmvK2F9NF0b8RfomvI4Bx06hR6mRJdbE5+EmO15wu4mcv0bcBJ12Q/0JiXsCwOqqaO4uCWe YDqOGU= X-Google-Smtp-Source: AGHT+IH8VGLj38MvyBD6pvIJvYO9YQppIhSVxE3G2Z58WKLdj6jjmW84wh2E8SS/8g7Qk/Bln0c8507igUK/0s2TDbA= X-Received: by 2002:a05:690c:f0e:b0:71a:5a8:d889 with SMTP id 00721157ae682-71a4668f72fmr105028877b3.28.1753942542780; Wed, 30 Jul 2025 23:15:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <26D77653-F0F6-4156-ADBA-86D9955C45B8@nicksdot.dev> In-Reply-To: <26D77653-F0F6-4156-ADBA-86D9955C45B8@nicksdot.dev> Date: Thu, 31 Jul 2025 11:15:31 +0500 X-Gm-Features: Ac12FXzHMqcqaiiP69CMydJwVBDRPRJ0cDjSRhh0hHEZEtAsSBg_7MFSeryL2jo Message-ID: Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body To: php@nicksdot.dev Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000380e6e063b33925b" From: 91liahim@gmail.com (Mihail Liahimov) --000000000000380e6e063b33925b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Nick! It still would be required because we're catching this concrete exception. Not catching all of throwables. =D1=87=D1=82, 31 =D0=B8=D1=8E=D0=BB. 2025=E2=80=AF=D0=B3. =D0=B2 10:43, Nic= k : > > > 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 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: > > 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=E2=80=99t u= sed? > > *Cheers,* > Nick > --000000000000380e6e063b33925b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,=C2=A0Nick!

It still would be r= equired because we're catching this concrete=C2=A0exception. Not catchi= ng all of throwables.

=D1=87=D1=82, 31 =D0=B8=D1=8E=D0= =BB. 2025=E2=80=AF=D0=B3. =D0=B2 10:43, Nick <php@nicksdot.dev>:


On 31. Jul 2025, at 11= :53, Mihail Liahimov <91liahim@gmail.com> wrote:

Intr= oduction

Currently, PHP requires a block body for catch clauses even= when the caught exception is not used. This results in unnecessary boilerp= late 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 {
=C2=A0 =C2=A0 // code = that may throw
} catch (SomeError);

This would be equivalent to:<= br>
try {
=C2=A0 =C2=A0 // code that may throw
} catch (SomeError)= {}

Motivation

Reduced Boilerplate: Eliminates unnecessary em= pty 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 addit= ive change to the syntax.


Hey Mihail,

Why = would the `catch (SomeError)` still be required if it isn=E2=80=99t used?

Cheers,
Nick
--000000000000380e6e063b33925b--