I have the next example using jQuery:
try{
   $.post(url,data, function(response){
       throw 'Exception';
   });
}catch(e){
      alert('Error'); 
}
But the line: alert('Error') is never executed. What is happening here?
I have the next example using jQuery:
try{
   $.post(url,data, function(response){
       throw 'Exception';
   });
}catch(e){
      alert('Error'); 
}
But the line: alert('Error') is never executed. What is happening here?
 
    
    You're exception is thrown asynchronously, so the exception will not be caught.
The correct way to deal with this is
$.post(url,data, function(response){
   throw 'Exception';
}).catch(function(ex){
    alert('Error'); 
});
