Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127211 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A66CD1A00BC for ; Sun, 27 Apr 2025 20:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745787310; bh=5c2KWMJf4QMbf0INWAp7vKjjpq9SZeO2lFw4xFovgWc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=QkuZj3ONa8LZ+zAqvpHBwm5eScVtleoKvnJSO1VmwV1+zKZkx93MWGuNwtV6RbWNz rx2dV9QtnbyNXf2CYr30GmE+nkjbYl50+0BGStUPuupgmPREU4XEUKZTVdVbT4ZY+B qj5DWWCJCwGt+hWmbEmj608zDA+rJvhJhp7dnMfDmwjT+LxA9oVw9CEGsWesmWNH3k tilpfDcal7scMwb1n/nTAn6HkHpuyo40QaSaXx/ir0SnzkUdQPVGntlEK6TBzXMmMy S4+N4LVOQc9g4XJZsbdypKG6louyytRyfz/PkmswvDtHp6WORBnsDL7nrB8RKlZqCC NgPLnvgtgKwNA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5248B1801D4 for ; Sun, 27 Apr 2025 20:55:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 27 Apr 2025 20:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1745787446; bh=j7PUO4WZYVpJ6tZSgy8+5Ec9RnhB2EB4JSOsZfDkUf4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=mBbnrkIpmgd0sTjStRdCv6VYwf9PtOr/aP8V9/GVPMsFfjLcMf22ifAWorbXbatu7 Gh8ZXaIfI9vCz6VpkFDbx9y7EwAYUG1nn6d9fv97wL39MphGGMMpekzRvoCUS7tpjw fRhxCjGQemfQ7XeQFKhM7JdyutgyjyV0oZvIpaccjIFqJI+CozsgHOUKPyQ6uii7AN qiNhudsawApwSV+zQBFmyHddy4BrR9GkzFQT0IAT1elwNqiFuuhE+te2MIROkVbmx8 Lq5VM5Qf6LJQsxBa+OVXE0gEYVAd+rPU5oEPUhVrfw9rLPAsIypU1sf/UzQJPV3AXN IFPcRjn4vKLWA== Message-ID: Date: Sun, 27 Apr 2025 22:57:24 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] Throwable Hierarchy Policy for Extensions To: Kamil Tekiela Cc: PHP internals , "Gina P. Banyard" References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 4/27/25 22:40, Kamil Tekiela wrote: >> The exception message MUST NOT be the only property that allows to > differentiate different types of error that the user may be interested in. > > What does this mean exactly? Can you give an example? This is intended to say “if a user calls ->getMessage() and consumes it in an `if()` statement, then you are doing it wrong” and “the error message is intended for human consumption and changes to the message are not considered breaking changes”. Ideally different exception classes should be used, but using the `$code` property to differentiate between different types of error is also acceptable when there is a wide range of errors the user might be interested in. For PDO this might be: PdoException extends Exception PdoError extends Error UnsuccessfulQueryException extends PdoException QuerySyntaxError extends PdoError And then in UnsuccessfulQueryException, use a different code for "Duplicate entry", "Query timed out", and "Deadlock" to avoid adding a separate class for each failure case. It might make sense to add classes for the failure cases that are most likely to require special handling. e.g. a DeadlockException to retry the transaction. But as a user I should not need to do: again: try { $query->execute(); } catch (UnsuccessfulQueryException $e) { if (str_contains($e->getMessage(), 'Timeout')) { goto again; } throw $e } to determine whether it was a timeout, a deadlock or a duplicate entry. Do you have a wording suggestion to make it clearer what is meant by that sentence? Best regards Tim Düsterhus