vrana           Fri Aug 17 12:31:46 2007 UTC

  Modified files:              
    /phpdoc/en/language exceptions.xml 
  Log:
  Better example (bug #39258)
  
http://cvs.php.net/viewvc.cgi/phpdoc/en/language/exceptions.xml?r1=1.3&r2=1.4&diff_format=u
Index: phpdoc/en/language/exceptions.xml
diff -u phpdoc/en/language/exceptions.xml:1.3 
phpdoc/en/language/exceptions.xml:1.4
--- phpdoc/en/language/exceptions.xml:1.3       Wed Jun 20 22:24:12 2007
+++ phpdoc/en/language/exceptions.xml   Fri Aug 17 12:31:46 2007
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
  <chapter xml:id="language.exceptions" xmlns="http://docbook.org/ns/docbook";>
   <title>Exceptions</title>
 
@@ -30,13 +30,16 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-try {
-    $error = 'Always throw this error';
-    throw new Exception($error);
-
-    // Code following an exception is not executed.
-    echo 'Never executed';
+function inverse($x) {
+    if (!$x) {
+        throw new Exception('Division by zero.');
+    }
+    else return 1/$x;
+}
 
+try {
+    echo inverse(5) . "\n";
+    echo inverse(0) . "\n";
 } catch (Exception $e) {
     echo 'Caught exception: ',  $e->getMessage(), "\n";
 }
@@ -46,6 +49,14 @@
 ?>
 ]]>
     </programlisting>
+    &example.outputs;
+    <screen>
+<![CDATA[
+0.2
+Division by zero.
+Hello World
+]]>
+    </screen>
    </example>
 
   <sect1 xml:id="language.exceptions.extending">

Reply via email to