There are two types of Exceptions which is caught by jQuery
1. When exception object is in the form of JSON object.
2. When exception object is in the form of plain text or HTML.
WebMethod for testing both types
In order to test both the cases I have created the following WebMethod which simply tries to convert the received string value to integer.
[System.Web.Services.WebMethod]
public static void ValidateNumber(string number)
{
int no = Convert.ToInt32(number);
}
function tc(func, msg) {
msg = msg || "Handler exception";
return function(e) {
try {
return func(e);
}
catch (exc) {
$.post( /* send exception to server? */ );
throw exc; // let nature take its course
}
};
}
___________________________________________________________________________________
try {  // Your code goes here… }
catch(err) { // Handle the error here. }
finally { // Code always executed regardless of the result.
}
___________________________________________________________________________________
jQuery.readyException() - Handles the errors thrown synchronously in functions wrapped in $.jQuery.
By default it re-throws the error in a timeout so that it's logged in the console and passed to window.onerror instead of being swallowed.
jQuery.readyException = function(error) {
console.error( error );
};
___________________________________________________________________________________