Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127196 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 14DDD1A00BC for ; Sun, 27 Apr 2025 11:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745752967; bh=VWlyIWkv/fu67+AETms5bXbwTLi7aTvVn+P4HdGwSSw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PXeBqUiVZxAT9/lsoMZ8qzFHUO/zLWS0eZNQBpUbMt6c67Nos8r4y9Wyi5YaViKSp OrmqtB16WjZ1VMuPhrBfIvlXwZaAfFIyfczhaM88qteHTtzp7PVV8jl7VHMt7GJ089 6bV39rsZ7VGMitDU+oV+KOkAKTbHA4gG+jthBW7lk8PcA1bpU400cEedsh3aqtzWMK jvV9+VdgqSGnfdw1z7kN83xOCSMiMbeaDErYSCAj7nsRWDIz9RZCD+287Y1aM/k1hO 54DerOKVHE6syk4bwUJlM4vVF+IY3risT+YK2jEItcvInEZJeGJgrlBZzeQelVURUy afpATaSy+DQYQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0460918006D for ; Sun, 27 Apr 2025 11:22:46 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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 mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 11:22:45 +0000 (UTC) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e730b8d934aso2525056276.2 for ; Sun, 27 Apr 2025 04:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech.net; s=google; t=1745753102; x=1746357902; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VWlyIWkv/fu67+AETms5bXbwTLi7aTvVn+P4HdGwSSw=; b=DmQrV8Zi5WP2pdRoFN6CECcL44wPd3HC4y2sB/rkAWBsIJdsSOd6vfcPMDUQY0JxQZ 2BjfGG6hDqgcs9+dzXmmByygIQ//VBTNE9IqLGQzDKvkqxVLy0vjA92jeN+JY5cljqD4 H4GUFJFGQIibsAP9lZNNgWhrNvseMmcnmv9BAPWzs8e3ibE0BxDv5V1cBuINVPTc4sOg tBV+7R0qLyvB9GPCjM0AzW37chd0AUJ+i6mZra+ZK6F12A1arHDaq/ONB46RwfjHSehg 3/JigXr27odWP9qZahizwapJNFpYF+7CIm8B4kaVVSC3cX4XPhbOgQB4Hc2zrxDj/X+8 cv/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745753102; x=1746357902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VWlyIWkv/fu67+AETms5bXbwTLi7aTvVn+P4HdGwSSw=; b=sXthEyUpEO/lQ7iQWLmY3+Uc4Ohpl+06fEMt52Eg30M3Mxcezr4Z5dLFlYYC5a1qCm Kcf7kmCGPnjgaX4fcGaGiCK4+XUk0fmfA1iuPtIGqlzwRklJ2d+9yE5QF85WOmUYkLvR uLa6QwioAjPYHzvimD3Eb4kqrz9BJQqMPjifXVA9Q1RIGrRb+tfKfatMyNIeb5KmBTdj 3mK4YqfcIWd9UHtV+ie7TWH41ZTs/kLdzl39KWO8YpEgfOnuL+0NM03xjv22iKP7iEM5 OMNAeptp9lyxWfwrqgc7yBjxm5ccm6O9y6bRZHS23n96guQSu9WR7GMjS14Y+ChSjaFS qyhA== X-Forwarded-Encrypted: i=1; AJvYcCVAwRkbQ0mTf5OUgil3u9KfYC1lDiE6eTJpXpu0QcWmVw/bOtWG+23UwC9ETxVRg57lpfk5kwyVXlg=@lists.php.net X-Gm-Message-State: AOJu0YxqPKw+8YrIbcxPct+w7s41dH/d90tWbCAvdN872Sk4ct949IQx muI9EICuLZeI1thPhAH8YgH23aWsBNrU3Wf/KCSFrU4YuPQM6M8LdD0FVv/ex73EyAEp4s/d6dj l3EWf49Yw+pp7SxQiOAO00ZpvJZsiR8ftZDvHzA== X-Gm-Gg: ASbGncsGkxpHFfvMDXbGH5pvDOwng/Z0dUw+QAbD5+obAIgCYYZ1xWMr7lNMgcJsevG QDS9jtHeg+o7ScPsB+pQW3na1yRGVekTlqAbAiGPdpH4S4d9J43DZyGk1OfU8z3SJjKtQyRL3qD 9UZD08y+EDlBG78boGHleOPbuV+t+s5gI= X-Google-Smtp-Source: AGHT+IGFDwNT4+Cu7joK1gcEbv44PBgEWqnWItHOd5ErNgWX3jzrbMzTtOY9JJ+zGYtrma/Lmztwi/ISRRspIJ2rrfU= X-Received: by 2002:a05:6902:1692:b0:e73:31c0:5477 with SMTP id 3f1490d57ef6-e7331c06124mr3714674276.18.1745753102576; Sun, 27 Apr 2025 04:25:02 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <39597a9c-6854-40c6-a529-32b2b178cb27@app.fastmail.com> <64f44c6f-a1ef-4a26-9063-d4d90fdf678c@app.fastmail.com> In-Reply-To: <64f44c6f-a1ef-4a26-9063-d4d90fdf678c@app.fastmail.com> Date: Sun, 27 Apr 2025 13:24:51 +0200 X-Gm-Features: ATxdqUFwfU_S8eQ5J0r6IwxGBixNFj1grLlNdEzQBxD1xBV7QW0LRjh3oadOnrI Message-ID: Subject: Re: [PHP-DEV] Concept: Lightweight error channels To: Rob Landers Cc: Edmond Dantes , Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: andreas@dqxtech.net (Andreas Hennings) On Sun, 27 Apr 2025 at 10:27, Rob Landers wrote: > > On Sun, Apr 27, 2025, at 10:16, Edmond Dantes wrote: > > Good afternoon, Larry. > > Looking at the comparison table, it seems that the two most important dif= ferences are: > > Backtrace consumes a lot of resources. > > There is an explicit contract for exceptions thrown by a function. > > I didn't fully understand the point about the exception hierarchy, but it= seems important too. > > It seems to me that the Backtrace issue is a problem of a low level of ab= straction =E2=80=94 the implementation of exceptions. That's one problem. T= he lack of an explicit contract is a problem on a completely different leve= l of abstraction. > > The issue with the missing contract could have been solved even for excep= tions, without creating a new entity. > > Regarding Backtrace, the following questions seem fair: > > What if I want to know where the situation occurred? Can I just ignore th= is information? For the type of failure we are talking about, there is not really the need for a backtrace. > > If yes, why not create an option to disable backtrace generation for exce= ptions? > > Regarding the Result/Error type. > > I have experience using this approach in remote services, where exception= s seem inappropriate. > It=E2=80=99s probably possible to use it even now without generics, and w= ithout any special language features. > > What if we focus on: > > Improving exception handling, making it as lightweight as in Python. > > Introducing explicit exception contracts. > > Best Regards, Ed. > > > I'm not going to lie, I spent nearly an hour last night attempting to cre= ate an exception without a stack trace. I was quite surprised at how imposs= ible it is. The engine really goes out of its way to ensure the trace is se= t. One thing you can do is throw the same exception again. Not really a good solution though. > > A simple solution (for this problem) may be creating a new exception type= \LightException or something that would allow for never setting a stack tr= ace. This is pretty heavily on the "pragmatic" side of the solution space, = but it is also relatively simple. The main obstacle here is interface Throwable which promises to have a file, line number and backtrace. Currently you can only throw objects that implement Throwable. https://3v4l.org/LHhNm If we introduce a "LightException", it cannot really extend Exception, because then it gets all the baggage. The solution could be a new interface "Catchable" or "Raisable". But this would be superfluous. Instead, we could allow to throw any objects, or introduce a new keyword "raise", that would allow any objects. On the implementing side, a "raise new NotFound(..)" seems mostly the same as "throw new NotFound(..)". On the declaration side, we might want to add " ... throws NotFound" or "... raises NotFound", to make this part of the contract. So this would be very similar to checked exceptions as I know them from Java. On the calling (and handling) side, any alternative we find to "try ... catch (...) ..." might also be useful for regular exceptions. In fact this would be the big difference to current exceptions and return values in terms of developer experience, whereas the "no stack trace overhead" is more an internal thing. --- Andreas > > =E2=80=94 Rob