Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url YII 1错误和异常处理_Url_Exception_Yii_Error Handling_Exception Handling - Fatal编程技术网

Url YII 1错误和异常处理

Url YII 1错误和异常处理,url,exception,yii,error-handling,exception-handling,Url,Exception,Yii,Error Handling,Exception Handling,如何在yii中处理CHttpException。若有人输入了错误的url,那个么我想将用户重定向到一个特定的页面。我可以处理除法0错误,但无法处理CHttpException我在模块>组件>控制器中编写此代码 public function init() { parent::init(); Yii::app()->attachEventHandler('onError',array($this,'handleError'));

如何在yii中处理CHttpException。若有人输入了错误的url,那个么我想将用户重定向到一个特定的页面。我可以处理除法0错误,但无法处理CHttpException
我在模块>组件>控制器中编写此代码

    public function init()
    {
        parent::init();
        Yii::app()->attachEventHandler('onError',array($this,'handleError'));
        Yii::app()->attachEventHandler('onException',array($this,'handleError'));
    }

    public function handleError(CEvent $event)
    {

        if ($event instanceof CExceptionEvent)
        if ($event instanceof CHttpException)
        {
            // some logics
        }
        elseif($event instanceof CErrorEvent)
        {
            $arr[0]=$event->code;
            $arr[1]=$event->message;

            $this->render("application.views.site.error", array('event' => $arr));
        }
        $event->handled = TRUE;
    }

现场控制器:

public function actionError()
    {
        $this->layout = "viewsLayout";
        if ($error = Yii::app()->errorHandler->error) {
            if (Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

先生实际上问题是如何检测CHttpException?使用try{}catch{}语句检测异常,