Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58257 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18772 invoked from network); 28 Feb 2012 16:54:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2012 16:54:50 -0000 Authentication-Results: pb1.pair.com header.from=kiall@managedit.ie; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kiall@managedit.ie; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain managedit.ie designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: kiall@managedit.ie X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:58123] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/34-34356-9D60D4F4 for ; Tue, 28 Feb 2012 11:54:50 -0500 Received: by bkcje9 with SMTP id je9so431215bkc.29 for ; Tue, 28 Feb 2012 08:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of kiall@managedit.ie designates 10.205.117.141 as permitted sender) client-ip=10.205.117.141; Authentication-Results: mr.google.com; spf=pass (google.com: domain of kiall@managedit.ie designates 10.205.117.141 as permitted sender) smtp.mail=kiall@managedit.ie; dkim=pass header.i=kiall@managedit.ie Received: from mr.google.com ([10.205.117.141]) by 10.205.117.141 with SMTP id fm13mr9596833bkc.133.1330448086604 (num_hops = 1); Tue, 28 Feb 2012 08:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=managedit.ie; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=GwSk8y1auTISpHG8KgpA4bUzjeEQSv8fq4zFkQ1GbMQ=; b=R/k6AAwizb8xHYD9AQO+u/ziFMbRkDSy78QSfYAyY4nIYvGUC3dADrPzfxC+IClp5j YV6yqVikVTSlqpprROUnGH75wluDKDw0HyiZW6guxVmslvYBHAyHYgEJGqORAI0t2Wco yfSsHe2YobkkxWLZEdPpguonDiR7Jqz171oF8= Received: by 10.205.117.141 with SMTP id fm13mr7735456bkc.133.1330448086316; Tue, 28 Feb 2012 08:54:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.204.42.74 with HTTP; Tue, 28 Feb 2012 08:54:26 -0800 (PST) In-Reply-To: References: <01a901ccf622$0645f230$12d1d690$@alliantinternet.com> Date: Tue, 28 Feb 2012 16:54:26 +0000 Message-ID: To: Tom Boutell Cc: Arvids Godjuks , Richard Lynch , internals@lists.php.net Content-Type: multipart/alternative; boundary=000e0cdfcbcc93b72404ba091567 X-Gm-Message-State: ALoCoQkaLSUQ2ADV1oXc69VudqR8s4xiRXO7QpGCVQievtVg3vdVnMbqAaLgl7tIp2rEtSZOKnWu Subject: Re: [PHP-DEV] Possibility to add finally to try/catch? From: kiall@managedit.ie (Kiall Mac Innes) --000e0cdfcbcc93b72404ba091567 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Feb 28, 2012 at 4:48 PM, Tom Boutell wrote: > On Tue, Feb 28, 2012 at 11:32 AM, Kiall Mac Innes > wrote: > > Yes, You could abstract the try/catch into a new (and un-needed) function > > to try and emulate the behavior of finally.. Unless, for example, you > > re-throw the exception after logging in the catch. > > 'finally' doesn't run for stuff that throws an exception not caught in > the try { } block, or an exception thrown again in the catch { } block > - does it? > > I would hope not, since that means "something this block of code did > not anticipate at all - another sort of exceptional situation > altogether" and really should not run any more local code, nothing > until and unless there is a catch block somewhere further up that does > catch that exception. > I would indeed expect the finally to run regardless of what happens in the catch block. $ python >>> def divide(x, y): ... try: ... result = x / y ... except ZeroDivisionError: ... print "division by zero!" ... raise Exception('division by zero') ... else: ... print "result is", result ... finally: ... print "executing finally clause" ... >>> divide(2, 1) result is 2 executing finally clause >>> >>> divide(2, 0) division by zero! executing finally clause <====== The interesting part Traceback (most recent call last): File "", line 1, in File "", line 6, in divide Exception: division by zero >>> >>> divide("2", "1") executing finally clause Traceback (most recent call last): File "", line 1, in File "", line 3, in divide TypeError: unsupported operand type(s) for /: 'str' and 'str' --000e0cdfcbcc93b72404ba091567--