cvs: phpdoc-zh /language exceptions.xml

From: Date: Wed, 17 Dec 2008 09:27:32 +0000
Subject: cvs: phpdoc-zh /language exceptions.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-3119@lists.php.net to get a copy of this message
eniac2008 Wed Dec 17 09:27:32 2008 UTC Modified files: /phpdoc-zh/language exceptions.xml Log: Sync with EN-Revision 1.8 http://cvs.php.net/viewvc.cgi/phpdoc-zh/language/exceptions.xml?r1=1.6&r2=1.7&diff_format=u Index: phpdoc-zh/language/exceptions.xml diff -u phpdoc-zh/language/exceptions.xml:1.6 phpdoc-zh/language/exceptions.xml:1.7 --- phpdoc-zh/language/exceptions.xml:1.6 Sat Jun 23 13:32:42 2007 +++ phpdoc-zh/language/exceptions.xml Wed Dec 17 09:27:32 2008 @@ -1,7 +1,8 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.6 $ --> -<!-- $Author: bjori $ --> -<!-- EN-Revision: 1.3 Maintainer: lm92 Status: ready --> +<!-- $Revision: 1.7 $ --> +<!-- $Author: eniac2008 $ --> +<!-- EN-Revision: 1.8 Maintainer: Altair Status: ready --> +<!-- CREDITS: lm92 --> <chapter xml:id="language.exceptions" xmlns="http://docbook.org/ns/docbook"> <title>Òì³£´¦Àí</title> @@ -24,27 +25,89 @@ ½«»á²úÉúÒ»¸öÑÏÖØµÄ´íÎ󣬲¢ÇÒÊä³ö <literal>Uncaught Exception ...</literal> £¨Î´²¶»ñÒì³££©µÄÌáʾÐÅÏ¢¡£ </para> + <note> + <para> + PHP ÄÚ²¿º¯ÊýÖ÷ҪʹÓÃ<link + linkend="ini.error-reporting">´íÎ󱨸æ</link>, Ö»ÓÐÏÖ´ú<link + linkend="language.oop5">ÃæÏò¶ÔÏó</link>µÄÀ©Õ¹²ÅʹÓÃÒì³£¡£µ«´íÎó¿ÉÒÔºÜÈÝÒ×µÄͨ¹ý<link + linkend="class.errorexception">ErrorException</link>ת»»ÎªÒì³£¡£ + </para> + </note> + <tip> + <para> + <link linkend="intro.spl">PHP±ê×¼¿â (SPL)</link> ÌṩÁËÐí¶àÄÚ½¨µÄÒì³£Àà¡£ + </para> + </tip> <example> <title>Å׳öÒ»¸öÒì³£</title> <programlisting role="php"> <![CDATA[ +<![CDATA[ <?php -try { - $error = 'Always throw this error'; - throw new Exception($error); - - // ´ÓÕâÀ↑ʼ£¬tra ´úÂë¿éÄڵĴúÂ뽫²»»á±»Ö´ÐÐ - 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"; } -// ¼ÌÐøÖ´ÐÐ +// Continue execution echo 'Hello World'; ?> ]]> </programlisting> + &example.outputs; + <screen> +<![CDATA[ +0.2 +Caught exception: Division by zero. +Hello World +]]> + </screen> + </example> + + <example> + <title>ǶÌ×µÄÒì³£</title> + <programlisting role="php"> +<![CDATA[ +<?php + +class MyException extends Exception { } + +class Test { + public function testing() { + try { + try { + throw new MyException('foo!'); + } catch (MyException $e) { + /* rethrow it */ + throw $e; + } + } catch (Exception $e) { + var_dump($e->getMessage()); + } + } +} + +$foo = new Test; +$foo->testing(); + +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +string(4) "foo!" +]]> + </screen> </example> <sect1 xml:id="language.exceptions.extending">

« previous php.doc.zh (#3119) next »