svn: /phpdoc/ja/trunk/language/ exceptions.xml

[email protected] (Yoshinari Takaoka)
Newsgroups php.doc.ja
Message-ID <[email protected]>
mumumu                                   Wed, 05 Feb 2020 21:22:57 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=349136

Log:
Clarification on interaction between finally and return statements (doc bug #68290)

Patch by Sorin Nunca

Bug: https://bugs.php.net/68290 (Closed) "finally" keyword barely explained
      
Changed paths:
    U   phpdoc/ja/trunk/language/exceptions.xml

Modified: phpdoc/ja/trunk/language/exceptions.xml
===================================================================
--- phpdoc/ja/trunk/language/exceptions.xml	2020-02-05 20:17:41 UTC (rev 349135)
+++ phpdoc/ja/trunk/language/exceptions.xml	2020-02-05 21:22:57 UTC (rev 349136)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- $Revision$ -->
-<!-- EN-Revision: 346158 Maintainer: hirokawa Status: ready -->
+<!-- EN-Revision: 349132 Maintainer: hirokawa Status: ready -->
 <!-- CREDITS: takagi,mumumu -->

 <chapter xml:id="language.exceptions" xmlns="http://docbook.org/ns/docbook">
@@ -261,6 +261,15 @@
     パイプ文字 (<literal>|</literal>) を使って指定できるようになりました。
     これは、異なるクラス改装からの例外を同時に扱う必要がある場合に有用です。
    </para>
+   <para>
+    &finally; ブロックと &return; 文の間には注意すべき相互作用があります。
+    &return; 文が &try; や &catch; ブロックの内部に存在した場合でも、
+    &finally; ブロックは実行されます。
+    さらに、&return; 文は出現した時に評価されますが、
+    結果は &finally; ブロックが実行された後に返されます。
+    さらに、&finally; ブロックにも &return; 文が存在した場合は、
+    &finally; ブロックから値が返されます。
+   </para>
   </simplesect>
   <simplesect xml:id="language.exceptions.finally">
    <title><literal>finally</literal></title>
@@ -332,7 +341,7 @@
     </screen>
    </example>
    <example>
-    <title>例外処理での <literal>finally</literal> ブロック</title>
+    <title>例外処理での &finally; ブロック</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -376,6 +385,33 @@
     </screen>
    </example>
    <example>
+    <title>&finally; ブロックと &return; の相互作用</title>
+    <programlisting role="php">
+<![CDATA[
+<?php
+
+function test() {
+    try {
+        throw new Exception('foo');
+    } catch (Exception $e) {
+        return 'catch';
+    } finally {
+        return 'finally';
+    }
+}
+
+echo test();
+?>
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+finally
+]]>
+    </screen>
+   </example>
+   <example>
     <title>ネストした例外</title>
     <programlisting role="php">
 <![CDATA[
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.