The following example makes a synchronous callback to the server with two numbers (49583 and 83924)
and the server-side method returns the sum of the numbers.
First of all, to be able to debug, we will need to set ThrowExceptionsAtClient
property to True
See also: Server-Side
Here is the Callback code without error handling:
alert("The sum is: " + ob_post.post(null, "onSum"));
There are a few errors that can occur when making a callback with data.
We will give examples of 4 such errors:
Processing file is not found (throws CallbackError exception).
Server method is not found (throws ServerMethodNotImplemented exception).
An argument is of a different type than declared in the server method (throws InvalidCastException exception).
A user exception (in our case we'll throw an exception when the numbers are equal)
can occur on various ocasions:
The ServerFileName property is wrong.
There was a problem while processing the data server-side.
For example, if we are using a database, we can have several errors:
database not found, not having enough rights to
update the database and so on.
If the user doesn't throw a specific exception for this error,
then it will automatically throw the CallbackError exception.
The best way to handle errors is to throw an exception everytime needed,
so that we know exactly what is the error that occured.
We will make a few erroneous requests to see how we can handle the errors.
If the numbers are equal, then custom exception will be thrown from the server.
Here is the correct callback:
If the ServerFileName
If one of the arguments is not an integer:
Please check the debug for synchronous callback
and debug for asynchronous callback
examples to see how to handle the errors.