Better example (bug #39258)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@241437 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2007-08-17 12:31:46 +00:00
parent 836b535e0a
commit 72c4c8eb77

View file

@ -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
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
else return 1/$x;
}
try {
$error = 'Always throw this error';
throw new Exception($error);
// Code following an exception is not executed.
echo 'Never executed';
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
@ -46,6 +49,14 @@ echo 'Hello World';
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
0.2
Division by zero.
Hello World
]]>
</screen>
</example>
<sect1 xml:id="language.exceptions.extending">