国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php框架 > ZendFramework > ”凤毛麟角的ZendFramework“-2-Zend_Exception-1

”凤毛麟角的ZendFramework“-2-Zend_Exception-1

来源:程序员人生   发布时间:2014-03-29 19:32:08 阅读次数:3090次

Zend Framework 抛出的所有异常都必须是 Zend_Exception 的子类的对象。
class Zend_Exception extends Exception{    /**     * @var null|Exception     */    private $_previous = null;    /**     * Construct the exception     *     * @param  string $msg     * @param  int $code     * @param  Exception $previous     * @return void     */    public function __construct($msg = '', $code = 0, Exception $previous = null)    {        if (version_compare(PHP_VERSION, '5.3.0', '<')) {            parent::__construct($msg, (int) $code);            $this->_previous = $previous;        } else {            parent::__construct($msg, (int) $code, $previous);        }    }    /**     * Overloading     *     * For PHP < 5.3.0, provides access to the getPrevious() method.     *      * @param  string $method      * @param  array $args      * @return mixed     */    public function __call($method, array $args)    {        if ('getprevious' == strtolower($method)) {            return $this->_getPrevious();        }        return null;    }    /**     * String representation of the exception     *     * @return string     */    public function __toString()    {        if (version_compare(PHP_VERSION, '5.3.0', '<')) {            if (null !== ($e = $this->getPrevious())) {                return $e->__toString()                        . "Next "                        . parent::__toString();            }        }        return parent::__toString();    }    /**     * Returns previous Exception     *     * @return Exception|null     */    protected function _getPrevious()    {        return $this->_previous;    }}

Zend_Exception 注意集成了万能的Exception类,做了简单的封装。

具体的异常说明定义还需要根据具体情况自己定义。

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生