Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67382 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50958 invoked from network); 9 May 2013 22:50:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 May 2013 22:50:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.47 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.216.47 mail-qa0-f47.google.com Received: from [209.85.216.47] ([209.85.216.47:54431] helo=mail-qa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/80-45230-5482C815 for ; Thu, 09 May 2013 18:50:46 -0400 Received: by mail-qa0-f47.google.com with SMTP id i13so44917qae.6 for ; Thu, 09 May 2013 15:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=PjkegZP35v2Jv+xRd904Pc6r4JYxNevWY7W/WNSUmDg=; b=gtLA5kK1K9Ibu5zfOfFn4CbnUFEJgRsYfYOTJd8Bu3U71iZmqZLM2Ha/w2Kn4aybeQ X1hYrazxdldDLm6RWtAatdLYZGPEaHaNjOD/a3DX5x2vXXETXZtH1gsk5udkjb6Q77Ed hxobs+adxWYRj2Sp2PJZu7A7fPVzPoxvJXyuyGcNfKtBGmNRuFQTG3Xb2XpbzfU6W9a3 dHN0ihVkcCO5UDQow5w9wJD55q2MeprBn6wzDZ0+V6p/6c49nSwOqWlaYtA5h5RFzEsA qyiIE+2IKhuFbkS0KufzDixb7TbxPlghXKXwgIyVuZovvHrq9z1Zp/t17bnB0DkUOtxD DXtQ== X-Received: by 10.224.56.10 with SMTP id w10mr9985401qag.41.1368139841652; Thu, 09 May 2013 15:50:41 -0700 (PDT) MIME-Version: 1.0 Sender: ekneuss@gmail.com Received: by 10.49.87.70 with HTTP; Thu, 9 May 2013 15:50:21 -0700 (PDT) In-Reply-To: References: Date: Fri, 10 May 2013 00:50:21 +0200 X-Google-Sender-Auth: nU1Ug6PWUmpT-lqE9eMQPS7sZGs Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c2ffcc44ae9c04dc50e1d9 Subject: Re: [PHP-DEV] exceptions during __toString() From: colder@php.net (Etienne Kneuss) --001a11c2ffcc44ae9c04dc50e1d9 Content-Type: text/plain; charset=UTF-8 On Fri, May 10, 2013 at 12:00 AM, Rasmus Schultz wrote: > I just ran into this issue again: > > > http://stackoverflow.com/questions/2429642/why-its-impossible-to-throw-exception-from-tostring > > Instead of throwing some nonsense "you're not allowed to throw from here" > error-message, how about actually unwinding the stack and passing the > exception to the global exception-handler? > > I understand there's a technical limitation making it difficult/impossible > to handle exceptions during __toString() - and it looks like you can still > try {...} catch (Exception $e) in __toString() just fine, but then what? > You have the exception, but you have no way to pass it to the standard > global exception-handler. > > If the script has to terminate either way, why not terminate the same way > an unhandled exception would normally cause the script to terminate? > > E.g. output the actual error-message, or pass it to whatever was registered > with register_exception_handler() so it can be output or handled in the > usual way? > The reason is that toString can be triggered from a lot of internal places. If an exception is thrown and caught within toString, it's not a problem. The problem is if the exception escapes toString, because it thus means that the code invoking toString must be interrupted. We in fact have no guarantee that all those internal places will work consistently/correctly in the presence of an exception, and if the engine will remain in a state that allows executing code afterward. Not executing code means we need to bypass error handlers as well. Handling an exception from internal code is a "manual" procedure, and code written that relies on conversions to strings may not have been written with support for exceptions in mind. I guess the alternative approach is to allow exceptions, review the code (i.e. a lot of work), and eventually fix reports as they come in. Best, -- Etienne Kneuss --001a11c2ffcc44ae9c04dc50e1d9--