+ -
当前位置:首页 → 问答吧 → 一点小问题

一点小问题

时间:2008-01-11

来源:互联网

1.2.3. Other New Language FeaturesException handling.
PHP 5 adds the ability for the well-known TRy/throw/catch structured exception-handling paradigm. You are only allowed to throw objects that inherit from the Exception class:
复制PHP内容到剪贴板
PHP代码:
class SQLException extends Exception {    
             public $problem; 

             function __construct($problem) {       
                   $this->problem = $problem;    
             }
       }

       try {    ...    throw new SQLException("Couldn't connect to database");    ...} 
       catch (SQLException $e) {    print "Caught an SQLException with problem $obj->problem";} 
       catch (Exception $e) {    print "Caught unrecognized exception";}

Currently for backward-compatibility purposes, most internal functions do not throw exceptions. However, new extensions make use of this capability, and you can use it in your own source code. Also, similar to the already existing set_error_handler(), you may use set_exception_handler() to catch an unhandled exception before the script terminates.


注意这段中的example code第一个catch块,参数是$e,等到print的时候却是$obj->problem了。原文如是,翻译如是。虽然问题不大,但是很容易让新手产生误会。

另外,翻译到底算不算原创呢?

为什么国外的开源就那么彻底,而国内却做得如此的藏头露尾。《PHP5 POWER PROGRAMMING》可以免费的下载,《PHP5 权威编程》却要¥90RMB。

[ 本帖最后由 hosander 于 2008-1-12 15:30 编辑 ]

作者: eclanp   发布时间: 2008-01-11

这是一个问题,我已经记录下来了,另外我们会向原文出版社提出这个问题.

关于免费下载的问题,我向仁兄解释下,此书引入国内出版是需要跟原文的出版社购买中文版权的.所以出版社也有成本.

作者: hosander   发布时间: 2008-01-12

明白!纯属一时激动,谢谢。

正在努力学习OO,说实话,是真的很想要简老师的这本书。

作者: eclanp   发布时间: 2008-01-13

那就努力表现哦~~

作者: luzhou   发布时间: 2008-01-14

热门下载

更多