On Wed, Apr 30, 2025, at 1:06 PM, Tim Düsterhus wrote:
> Hi
>
> On 4/30/25 15:33, Larry Garfield wrote:
>> The only time I've seen anyone use $code is in TYPO3.  Their coding 
>> standards say that any time you throw an exception, you use the current 
>> timestamp (determined manually) as a code.  That way there is a globally 
>> unique code regardless of exception type that can be grepped to find the 
>> exact line it came from.
>
> To my understanding this would result in effectively identical 
> exceptions having different codes, just because checking the error 
> condition is split across different `if()` statements for readability? 
> That doesn't seem like a good idea - and that's why the RFC uses “cause” 
> as the wording of choice.

Correct.  There's 400 `throw new InvalidArgumentException('...', 123456798)` 
calls across the code base, each with a unique code number timestamp.

I didn't care for this approach either when I worked at TYPO3. :-)  My point 
being that I've rarely if ever seen $code used in a constructive and useful 
fashion.

>> […] just that it's the only time I've seen $code used in the wild...
>> 
>
> PDO (for better or worse) also uses the `$code` for the error code 
> returned by the database. Unfortunately it also widens the (untyped) 
> $code from int to string|int, which causes some issues, since folks only 
> expect int, since Exception::__construct() types the `$code` parameter 
> as `int`.
>
> Best regards
> Tim Düsterhus

In my experience, worse.  But that's another topic.

--Larry Garfield

Reply via email to