Throwing exception sends header info


(Sean Clarke) #1

Hi all,

forgive my possible ignorance here but can someone please tell me why throwing an Exception in Yii sends header information?

The following code fails to redirect:




try

{

    throw new Exception("New Exception");

} catch (Exception $ex) {

    Yii::app()->request->redirect("www.google.com");

}



any help appreciated.


(Alirz23) #2

help yourself


(Sean Clarke) #3

Thanks for the suggestion however this does not seem to work for me as my code is running from a static context, and I do not want the controller to catch the exception. I would like the static function which throws the exception to catch it without sending header information (if that’s possible)


(Kburton) #4

I think you just need to fix the URL to include the protocol:




Yii::app()->request->redirect("http://www.google.com");