Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119020 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8948 invoked from network); 21 Nov 2022 12:36:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Nov 2022 12:36:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 888471804F5 for ; Mon, 21 Nov 2022 04:36:05 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS30827 82.113.144.0/20 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Mon, 21 Nov 2022 04:36:04 -0800 (PST) Received: from [127.0.0.1] (unknown [85.255.233.224]) by xdebug.org (Postfix) with ESMTPSA id BF97B10C052; Mon, 21 Nov 2022 12:36:03 +0000 (GMT) Date: Mon, 21 Nov 2022 12:36:01 +0000 To: internals@lists.php.net, Vincent Langlet , PHP Internals List User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <707E8C39-F471-4C6F-B59C-A0D60D4C663E@php.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Using less generic exceptions for dates From: derick@php.net (Derick Rethans) On 21 November 2022 11:34:10 GMT, Vincent Langlet wrote: >Hi, > >When using json_encode or json_decode with the `JSON_THROW_ON_ERROR` flag= , >`JsonException` might be thrown=2E > >When using `new DateTime('foo')`, a generic `Exception` is thrown=2E >Incidentally, I wonder why it's not an `InvalidArgumentException` (but th= at >could be another debate)=2E > >But my main point is that I think it would be useful to use a specific >exception >``` >class DateException extends Exception {} >``` >- It allows a specific treatment when catching exceptions >- It allows a specific analysis when using static analysis tools like Psa= lm >or PHPStan=2E > >In a general way, I would say that PHP class/method should always use >scoped Exception instead of generics ones=2E > >I know nothing about how php is implemented but I would say introducing >DateException shouldn't be too hard and it's BC=2E What do you think ? I think this is a good idea and will add it to my todo list to investigate= =2E cheers Derick