Hi

On 3/28/24 14:30, Saki Takamachi wrote:
Thanks. Sorry, I meant "If I create dedicated exception classes, do I need 
separate classes for each type of error?” I couldn't write it well in English.

To answer this question, even if it is not necessary after all:

You should create separate classes for each type of error the user is expected to handle differently so that developers to not need to check the exception message to find out what the error was in their code.

Here's an insightful GitHub comment from Danack: https://github.com/php/php-src/pull/9071#issuecomment-1193162754

And here's the PR adding a proper Exception hierarchy to ext/random: https://github.com/php/php-src/pull/9220

For ext/date, here's the RFC adding the new Exception hierarchy: https://wiki.php.net/rfc/datetime-exceptions. If I remember correctly, the choices made for ext/date followed the precedent set by ext/random.

Best regards
Tim Düsterhus

Reply via email to