Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88962 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68962 invoked from network); 28 Oct 2015 10:15:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2015 10:15:03 -0000 Received: from [127.0.0.1] ([127.0.0.1:29763]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id F3/A0-63642-720A0365 for ; Wed, 28 Oct 2015 05:15:03 -0500 Authentication-Results: pb1.pair.com header.from=erik@evanv.nl; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=erik@evanv.nl; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain evanv.nl from 209.85.213.45 cause and error) X-PHP-List-Original-Sender: erik@evanv.nl X-Host-Fingerprint: 209.85.213.45 mail-vk0-f45.google.com Received: from [209.85.213.45] ([209.85.213.45:33421] helo=mail-vk0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/90-63642-8DC90365 for ; Wed, 28 Oct 2015 05:00:56 -0500 Received: by vkgy127 with SMTP id y127so1370508vkg.0 for ; Wed, 28 Oct 2015 03:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=evanv_nl.20150623.gappssmtp.com; s=20150623; h=mime-version:date:message-id:subject:from:to:content-type; bh=BwBundEYfdrAXAC8z3l+YwkWTkMrGQCiRFEuu50z8lg=; b=Wg6GnEZq3TNpBzmokXSQhC7i8fT/KpoJTDW0yQIilbOfoomN95LwSNi4iDNCMZ7z1M r8ho8ik8XIII7WM+QeJWP7d0Zw/lqcvu2jQcT19OVTVKVYUtOWVxPa0CO5RY9eTXuQgz I8Z1Wr9ttwtwOhPKR1HICJrq4+eK7P0eukSNociJePLfbIfbQW1sMj24P0pwVfIc809X pcMNOKkou/7177aFeCSL3i2w2AVMFqrl4LACCXqz88eVMGYHXWSIZ13o6GCb+l3gdW1n yzpRY59/Gga/1tx4e0f42rwlHYWwpwVnGFidZvjkYhETnNtsjqIE5I/YKn6iIQsfMi3r WrkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=BwBundEYfdrAXAC8z3l+YwkWTkMrGQCiRFEuu50z8lg=; b=B7uyy87b5iPUglH6Cyf0+aOdc9W7TmJR+bB4e7I40hQnBJYTWrzsCE6505Ay/KD802 cTif2jvinpnbLev6FZlK7djwCCWyBNKHYtdLM8XcsljP8K8OrobasrxxyPp5zAkzjYE8 sKRZnQC5suErpmIPvJJCCI+HkWZbBKzPcyC4nwP1QsfExSeiM7iEWhguIGf0N2btF/is h2B6NdvJ2TVSy2XBodzYDJmFYsN1UjCXOC76fQ55d4sBMLb0tN1R62wr7fK6vjDnzVzL CMy+kdhT9GHU8YuXVjQLJaEsrzcWpHZtjvXIcMBef04viNPQzXB5J0dNXPcsSrPRxGz6 ToDg== X-Gm-Message-State: ALoCoQnyOyFScXPd52gfHvU9cLVvsiZonFDFPJvdAnP2KRyn4MXLzCOO9L8/8Lvr45LTcKf9fL87 MIME-Version: 1.0 X-Received: by 10.31.161.146 with SMTP id k140mr33872417vke.90.1446026453739; Wed, 28 Oct 2015 03:00:53 -0700 (PDT) Received: by 10.31.92.83 with HTTP; Wed, 28 Oct 2015 03:00:53 -0700 (PDT) X-Originating-IP: [84.243.196.9] Date: Wed, 28 Oct 2015 11:00:53 +0100 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: In a destructor, how to detect if an exception is currently in flight? From: erik@evanv.nl (Erik van Velzen) Subject says it all. I want to make a small "ScopeGuard" library for exception-safe transactions, like the following: $scope = new ScopeGuard; $scope->onSucces(function() { logTransactionOne(); }); $scope->onFailure(function() { rollbackTransationOne(); }); doTransactionOne(); $scope->onSuccess(function() { logTransactionTwo(); }); $scope->onFailure(function() { rollbackTransactionTwo(); }); $scope->onFailure(function() { logFailureOfTransactionTwo(); }); doTransactionTwo(); // ... Three Four etc... So if an exception is thrown the attached onFailure callbacks will be executed, if the scope is exited through a return however the success callbacks will be executed. This requires me to know in ScopeGuard::__destruct() if the scope was left normally or due to an exception. The code in https://github.com/php/php-src/blob/master/Zend/zend_objects.c#L135 (line 135) seems to prevent me from knowing that information, because the exception is temporarily removed from the globals and put in a local variable. Is there any way to detect if an exception is currently in flight? (I've asked this same question on SO last week: http://stackoverflow.com/questions/33199997/in-destruct-how-can-you-see-if-an-exception-is-currently-in-flight)