Re: Using less generic exceptions for dates
| From: | Tim Düsterhus | Date: | Tue, 22 Nov 2022 08:53:41 +0000 |
| Subject: | Re: Using less generic exceptions for dates | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119022@lists.php.net to get a copy of this message | ||
Hi
On 11/21/22 13:36, Derick Rethans wrote:
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üsterhusBut my main point is that I think it would be useful to use a specific exceptionI think this is a good idea and will add it to my todo list to investigate.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 ?