Is there a clean, easy way to throw php exceptions through a json response jquery/ajax call.
As a complement to the previous answers, instead of repeating the same code for json encoding in all your exceptions, you could set an exception handler to be used only in the needed scripts. For instance:
function ajaxExceptionHandler($e) {
echo json_encode(array(
'error' => array(
'code' => $e->getCode(),
'msg' => $e->getMessage())
));
}
Then, in your ajax handler,
set_exception_handler('ajaxExceptionHandler');