Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88967 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87773 invoked from network); 28 Oct 2015 15:02:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2015 15:02:16 -0000 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.41 cause and error) X-PHP-List-Original-Sender: erik@evanv.nl X-Host-Fingerprint: 209.85.213.41 mail-vk0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:36779] helo=mail-vk0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/F2-63642-673E0365 for ; Wed, 28 Oct 2015 10:02:16 -0500 Received: by vkex70 with SMTP id x70so6595649vke.3 for ; Wed, 28 Oct 2015 08:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=evanv_nl.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=6bUOReusJfybUylSSBYlBAz9iG6tLFctZ+eCUlpbdW4=; b=bV9brRP0S3aNzr7V2bCjLbR+k1CFQtx8zLfBVtNw2gVoMz1x7lESgj1bcMMxZ7eEPy wOkHqF5v+xyYV5DidBC24G1wa9mArZ0xY6McxprS72ONIHXdyxr/PiN1rGLySynHtXFd 2F/W7XeA04PCaJoHQRgtAAPeK3nAMRfuDEoZVSpzry0tcg4x3HWZ4MmV+RSKi9pumzMv 0oOkmJTFOvGkZdOM3GoeX0GC/VoH2lxUEA+9qePobpp+Mj4x5OlNcbm4lwq6dufv/uN/ vZj7oXBuGjaKcLfXKdSyTyX3m4T+BMwUu/g8oWcOy7Sv+zdIp7L5A7GxjUlzZsRalTtm G0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=6bUOReusJfybUylSSBYlBAz9iG6tLFctZ+eCUlpbdW4=; b=V526kYBXaWUUZNYW6anRwEcySsi4nsM01OlNSoyH9hetSaaNcOl0MvkZxyb+tNrXPM NiXDlkJfIr7qDwy1dUbvJ6B368M4EFIs33YuB5aQ2ZyTsNDjAPmXsnUVo68Hiu6Xrz/c FFK1k4fuoTB6R/5qGi+kweP80Q/8QSa0fEOPi+mNzhKQJ0k12uim9lmKKyJGShPxXD54 zdjqhpyKL6wyu6sSB86GtTXfg7nZavKii2sIfM+U5Owa5vVE+2QcNbYf5g+OyoyX4SNY NvIIFTHbF31oLRhJeHOOksYzERqd0pLYQNkDKcAunO3i5O0B9Vq4slUHM8at/qLWE/hN 37uQ== X-Gm-Message-State: ALoCoQnyJ2yH0LidqMkDH61Bh7pBtbpoduYlOrME9Rx/b+9WpOOb/iMUZbzf0dZql3FKVr1XIKpp MIME-Version: 1.0 X-Received: by 10.31.130.71 with SMTP id e68mr19556149vkd.11.1446044531885; Wed, 28 Oct 2015 08:02:11 -0700 (PDT) Received: by 10.31.92.83 with HTTP; Wed, 28 Oct 2015 08:02:11 -0700 (PDT) X-Originating-IP: [84.243.196.9] In-Reply-To: <5630DE79.8070205@gmail.com> References: <5630DE79.8070205@gmail.com> Date: Wed, 28 Oct 2015 16:02:11 +0100 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] In a destructor, how to detect if an exception is currently in flight? From: erik@evanv.nl (Erik van Velzen) I didn't see how it could be generalized but your example clears that up. - Erik 2015-10-28 15:40 GMT+01:00 Rowan Collins : > > Did you see Johannes' suggestion re explicit success vs implicit failure? > > $scope = new ScopeGuard; > > $scope->onSucces(function() { logTransactionOne(); }); > $scope->onFailure(function() { rollbackTransationOne(); }); > doTransactionOne(); > > $scope->onSuccess(function() { logTransactionTwo(); }); > $scope->onFailure(function() { rollbackTransactionTwo(); }); > $scope->onExit(function() { cleanupTransactionTwo(); }); > doTransactionTwo(); > > $scope->registerSuccess(); > > > The ScopeGuard's destructor can now detect the condition: > > if ( $this->success_registered ) { > // Function reached checkpoint for this scope > $this->callSuccessHandlers(); > } else { > // Function aborted early, due to a throw or early return > $this->callExitHandlers(); > } > $this->callExitHandlers(); > > > No boilerplate throw-catch needed, works even if there is already a catch or > finally within the function's definition. > > In fact, I kind of want to use this somewhere now... ;) > > Regards, > -- > Rowan Collins > [IMSoP] >