We will use the same example used for the
no error handling example.
Here is how we should make a callback with the data correctly:
ob_post.AddParam("Number1", 49583);
ob_post.AddParam("Number2", 83924);
ob_post.post(null, 'onSum', clientFunction);
Next we will make the client side function with error handling, depending on the second argument of the function:
function clientFunction(result, ex){
if (ex != null){ // equivalent to if (result == null){
switch (ex.type){
case 'InvalidCastException':
// the code to execute when one of the arguments is not of the correct type
alert ('One of the arguments is not of the correct type.');
break;
case 'ServerMethodNotImplemented':
// the server-side method name is not implemented
alert ('The server-side method was not found.');
break;
case 'MyException':
// an error is thrown by the user at server-side
alert ('I threw this exception server-side');
break;
case 'CallbackError':
// there was an error server side
alert ('There was an error server-side.');
break;
}
}
else{
alert("The sum is: " + result);
}
}
We will use
ShowErrorsAtClient=false and
ThrowExceptionsAtClient=true so we can show our own alert messages.
Click to test the correct callback:
If the
ServerFileName is misspelled:
If the server method is misspelled:
If one of the arguments is not an integer:
If the numbers are equal:
You may also check the
debug for synchronous callback example to see the differences.