Exception Handling with php
Hi There,
I want to ask how to handle some exception in middle of the process (I'm working with PHP).
my js is :
- $(function(){
- var request;
- $('.naviref').on('click',function(){
- if(request){request.abort();}
- request = $.ajax({
- url: "html.php",
- type: "post"
- });
-
- request.done(function (response, textStatus, jqXHR){
- alert(response);
- var text = JSON.parse(response);
- alert(text);
- if(text.error){
- alert(1);}
- });
-
- request.fail(function (jqXHR, textStatus, errorThrown){
- alert('Error while making the request!');
-
- });
-
- event.preventDefault();
- });
- });
while in the php, the scenario is response the exception in the middle of the process :
- try{
- $a=20;
- $a=21;
- echo "the first letter : $a <br/>";
- throw new Exception("This is ERROR",0);
- echo "the second letter : $b <br/>";
- }
- catch(Exception $e){
- echo json_encode(array(
- 'error' => array(
- 'msg' => $e->getMessage()
- ),
- ));
- }
while test this code, alert output is
the first letter : 21 <br/>{"error":{"msg":"This is ERROR"}}
is there possible to check if there is an error in jquery and parse to another page (exception information page) ?