Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119022 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80458 invoked from network); 22 Nov 2022 08:53:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Nov 2022 08:53:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C234180054 for ; Tue, 22 Nov 2022 00:53:45 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Nov 2022 00:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1669107223; bh=cEEixjs1YQLk6zKs5ychnPLvf7fuAPb+Mgr8lMuzcBk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=KdEMePPxI8OGVQ7evICKwuzGpijhtBndOCptwmrRZufnPe8UzRsaSoQjIi9w6PVQb dejYXxr2eqempS1EmHGq9xI80uEvsBLNGkjwTcQaV4Jns/gnNamfLULLhHMfT3+APq DsRiiQb5pfkv4dUIm71xJcF2VJFdms4/zP6veg0/SqTuJPw1alARNgJ/86q+CN/Tg5 LY8cYBDjKy+RzYeGxEOpafpEVbMfcgWhp0iCS0Y0ckJ/mitx9/oq4cKP08ThHgN2/Q HxOzIMZnUBw0gRx1WWG6LnjjD8ODF+TVnC/Ma+A1mprhw//kzUa/937LBKEcZT/bD6 dQdkkP86EE+WA== Message-ID: Date: Tue, 22 Nov 2022 09:53:41 +0100 MIME-Version: 1.0 Content-Language: en-US To: Derick Rethans , internals@lists.php.net, Vincent Langlet References: <707E8C39-F471-4C6F-B59C-A0D60D4C663E@php.net> In-Reply-To: <707E8C39-F471-4C6F-B59C-A0D60D4C663E@php.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Using less generic exceptions for dates From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 11/21/22 13:36, Derick Rethans wrote: >> 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 Psalm >> or PHPStan. >> >> In a general way, I would say that PHP class/method should always use >> scoped Exception instead of generics ones. >> >> I know nothing about how php is implemented but I would say introducing >> DateException shouldn't be too hard and it's BC. What do you think ? > > I think this is a good idea and will add it to my todo list to investigate. > I agree that this is a good idea and would like to further recommend not having *just one* Exception, but several Exceptions to allow further differentiating the cause, e.g. class MalformedDateStringException extends DateException {} class UnrepresentableDateException extends DateException {} Related PR of mine to add the Exception hierarchy for PHP 8.2's ext/random: https://github.com/php/php-src/pull/9220 Best regards Tim Düsterhus