mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
836b535e0a
commit
72c4c8eb77
1 changed files with 18 additions and 7 deletions
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue