Throw a visible exception in an Ajax return

Is there an easy way to throw an exception e.g.:

throw new CHttpException(404,‘My AJAX thrown exception.’);

From within an ajax return and have that information displayed?

Ideally I would like the entire page to change to a custom error page. As it is now, nothing is shown to the user, nothing visibly changes on the page and execution halts but the exception message IS logged appropriately.

The same exception thrown on a non ajax page works fine and produces the expected error page from

$this->render(‘error’, $error);

from within site/error.

Have you specified an error callback for your ajax request?

I eventually got there and ended up doing that. I was hoping there was a Yii specific way to globally catch an exception from any AJAX return so that I don’t have to specify it in every Ajax link.


Can you please display your solution?