Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128335 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 932D51A00BC for ; Thu, 31 Jul 2025 09:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753953018; bh=1pGfJ8SIRXv42ZBzTdbwZATQ8DWuGumD1LVodsWHS3U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=j6iwidIgzVIZNgWVKjwNYio5+n/Fxo5wLITLEkAAiNTxRz1Ci1uKXPig8I+mR4fZy cJdXlJinFspMm89h9DuaEpTBZyhQc+POUje++0SqLvKMN5oEf55ijRYXbl36pSax+j xPi1W8IyD0/i4mq5nrG8KueHVwKdhBz+mjEmxQP5LGvMJzz1pGeT31SJtjN3YTbHDC hItajlX6CcTthF1MNwHBXvvruOuqNvpyYd0/iixMX5i+NVkfX5FazIvOoSIkuEKyWL 6Wbv2qrM5idwAIcW5TtKVmX5a5RQxgjKATqJcMw4IvYBGmD1TdLSglHlXaH3J7W3IA Oq9cofS3oqBOQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 68973180086 for ; Thu, 31 Jul 2025 09:10:17 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,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: Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 09:10:17 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-32b78b5aa39so6164691fa.1 for ; Thu, 31 Jul 2025 02:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753953118; x=1754557918; 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=QbMki0OkjCZAxG+KnCvKy0/G8tSnj+n1sOkkE3zLsM0=; b=EjyhQ9r4jr/HhmgqIXbZ3TCStxKQRfrFfXSWmf9BTbGfyCA4cNMqJ4P4kiQSYrq15j 2lXDszNsIDX8b1fMLWr1qbPMmCG05xz8dOt/CFkGlMLwHclMSKntKTCDfqPAIAqTf0y/ Ogi1galL/wo+Josu/fZeGh49emYDwnaRBWX/4z2VvN0/moV9Q6zmdkmQr1R2p+Cuqis3 mElZed+57gsjvoIm4NTW6D3jBCMLBBZTYheTPULFQr/Jg6MZ4FQTP5yeOEX1bF97+XRi fXY+cOPl7HobPTiIsseLkzCZjHst/fyGmrDJndX363VXNrxvUxqctPupRdzKRQjCIKWM Na9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753953118; x=1754557918; 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=QbMki0OkjCZAxG+KnCvKy0/G8tSnj+n1sOkkE3zLsM0=; b=Uy7/vjdBv+EV7/fVAV5Jofvm2er7X+Y6EqzYPIuB1UJyfalDUF1CQEg/kboEQqPIWb gICr3/j29rHeHHPOu2NiaqUrMjO0C0idUo7c9ltmpQXOEualVLuenUyLYSGaC27Ov26d guj9cQuQxj4lzWcmWirOR2y2s7wLFECROZzbT31RBBdYm11lEdMtqrKfkFrzwuVcz92I U/UTdd07lPV9QGKWtJEF6yKoqE7Co6xIKcd0JCJzXgFW1xBwrwdp4xZCayyPOVoHrxnW 63UM/sPmhE8SXS1fJZUmnHtzHPspGqBAYlE6o2Fro1AyW5QM6ZPXR8pADhY38tQ8kkc/ +mxg== X-Forwarded-Encrypted: i=1; AJvYcCXneJCy9b/1TcGqGmcAqH7ngVw90TeFWVHNG7/Qb/rQU5jYZ6U49NyXnNBYXQ6eZzNSDf3rqKCdANg=@lists.php.net X-Gm-Message-State: AOJu0YxU2Jpn7qBuCymsD6TOU5uVM2FFA5J9zwuSo/Qc40336V4cAGNv qS0WHRhVttjNxHBmd4SZrmnnzdu8b/fL2pvz6M45osobNwG9KqXTTLStO9+G+A4tkLMSaDbPM2O LJnfuhgvlAlM6BK2Mry1OCMOJ1qEtWmU= X-Gm-Gg: ASbGncv6CJHlI7HskoukzrCzWEYpGHWou3g2EJKGwGruTgvn7fBgECkw8DwHN+q/gVR r9CZ1LSQBRx8zT4KYhPkNIuqH4vwIsaENjCBELtGSmQkp5jN0H1y3KWOcNz2ZaquAb9OTQn9qgr IpJmt7GD9drCjspgxrHOmTIM5lVky3yoyCt+sbqfe6+JF1fz15pmpWNnsY0Qkew78K/5nm0Xd8c OdaZTLSBCIFZtDQZg== X-Google-Smtp-Source: AGHT+IFaC14YkZB4kFHRb92RtvED8Jxkp69G+Tk8KTe4jjA6sxhNUUZreVZoldx1l39SL6VvgjMwryP1VemTpE6yGkI= X-Received: by 2002:a05:651c:411c:b0:32c:bc69:e91d with SMTP id 38308e7fff4ca-33224c484a6mr16314691fa.39.1753953117272; Thu, 31 Jul 2025 02:11:57 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <095f25f5-695b-46d4-9f31-5d7e7a04ce05@rwec.co.uk> In-Reply-To: Date: Thu, 31 Jul 2025 12:11:43 +0300 X-Gm-Features: Ac12FXxGZ-UNb9Y5udY8xVd01FdYkfe0L2zp-M7mqnEQINZdVOV8kNWbELkAiWA Message-ID: Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body To: Lynn Cc: "Rowan Tommins [IMSoP]" , PHP internals Content-Type: multipart/alternative; boundary="00000000000081fe2b063b360809" From: tekiela246@gmail.com (Kamil Tekiela) --00000000000081fe2b063b360809 Content-Type: text/plain; charset="UTF-8" On Thu 31 Jul 2025, 11:32 Lynn, wrote: > > When I read `catch (Foo);` I read the intention of it being on purpose, > whereas `catch (Foo) {}` I can easily interpret as "the developer forgot to > handle the error" or "I can't tell if this is a bug or not". This often > requires something like: > ```php > try { > // ... > } catch (Foo) { > // do nothing > } > ``` > I much more prefer the long version and I'd rather see this in my code than just a semicolon or empty braces. If the developer must leave the catch block empty they better have a pretty good reason and they should clearly explain that in the code comment. Now the boilerplate has increased from {} vs ; to quite some extra, just to > ensure the intention. I don't know if omitting the body for this is the > solution, or if there's something else we can do like: `ignore(Foo, Bar)`. > When I read the code I want the intention to be clear, and an empty body > just makes me doubt whether or not it is intended and/or correct. I do > agree that empty catches are usually a sign of trouble, but realistically > speaking we don't always have control over the situation due to legacy or > vendor code. > > Just tossing some ideas out here: > ```php > $foo = try $this->doSomething() ignore (Foo, Bar); > > ignore(Foo, Bar) { > $foo = $this->doSomething(); > } catch (Throwable) { > // .... > } finally { > // ... > } > > try ignore(Foo, Bar) { > $foo = $this->doSomething(); > } catch (Throwable) { > // ... > } finally { > // ... > } > ``` > I read that as catch all exceptions apart from these which should bubble up to the next exception handler. It could be useful in its own too. I would vote NO to the proposal of short syntax for empty catch, not only because it's bad practice but also because it's one of the places where being very explicit is a good thing. An empty catch should be an eyesore and have a mandatory comment. It's akin to a door with a sign "don't open" versus a sign with "don't open, angry lions inside". > --00000000000081fe2b063b360809 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Thu 31 Jul 2025, 11:32 Lynn, = <kjarli@gmail.com> wrote:

When I read `catch (Foo);` I read the intention of it= being on purpose, whereas `catch (Foo) {}` I can easily interpret as "= ;the developer forgot to handle the error" or "I can't tell i= f this is a bug or not". This often requires something like:
```php
try {
=C2=A0 =C2=A0 // ...
} catch (F= oo) {
=C2=A0 =C2=A0 // do nothing
}
```
=

I much more prefer the long version and I'd rather see this i= n my code than just a semicolon or empty braces. If the developer must leav= e the catch block empty they better have a pretty good reason and they shou= ld clearly explain that in the code comment.=C2=A0
<= br>
Now the boilerplate has increased from {} vs ; to quite some extra, j= ust to ensure the intention. I don't know if omitting the body for this= is the solution, or if there's something else we can do like: `ignore(= Foo, Bar)`. When I read the code I want the intention to be clear, and an e= mpty body just makes me doubt whether or not it is intended and/or correct.= I do agree that empty catches are usually a sign of trouble, but realistic= ally speaking we don't always have control over the situation due to le= gacy or vendor code.

Just tossing some ideas out h= ere:
```php
$foo =3D try $this->doSomething() ignore= (Foo, Bar);

ignore(Foo, Bar) {
=C2=A0 = =C2=A0 $foo =3D $this->doSomething();
} catch (Throwable) {
=C2=A0 =C2=A0 // ....
} finally {
=C2= =A0 =C2=A0 // ...
}

try igno= re(Foo, Bar) {
=C2=A0 =C2=A0 $foo =3D $this->doSomething();
} catch (Throwable) {
=C2=A0 =C2=A0 // ...
} fi= nally {
=C2=A0 =C2=A0 // ...
}
```
I read that as catch all exceptions apart from the= se which should bubble up to the next exception handler. It could be useful= in its own too.=C2=A0

I= would vote NO to the proposal of short syntax for empty catch, not only be= cause it's bad practice but also because it's one of the places whe= re being very explicit is a good thing. An empty catch should be an eyesore= and have a mandatory comment. It's akin to a door with a sign "do= n't open" versus a sign with "don't open, angry lions ins= ide".=C2=A0
--00000000000081fe2b063b360809--