Dwr calling remote methods for error and exception handling

Source: Internet
Author: User

Remember when we used to call DWR the remote method is written like this

Remote.method (params,function (data) { 
//server-Side Execution-client logic, such as 
alert ("Returned after server execution:" +data);  
}); 
Remote.method (params,function (data) {
//server-Side Execution-client logic, such as
alert ("Returned after server execution:" +data);
});

The first to the penultimate parameter is the data that the client passes to the server, and the last parameter is directly a callback function. Because the JS code generated by the server based on the Java object is:

Remote.method = function (P0, callback) {
Dwr.engine._execute (remote._path, ' Remote ', ' method ', P0, callback); 
  
   }
  

So it's intuitive to interpret the second argument as a callback function. Of course, note that the remote method mentioned above is a parameter, and if it is multiple parameters, callback is always the last parameter, such as:

remote.method= function (P0, p1, callback) {
Dwr.engine._execute (remote._path, ' Remote ', ' method ', P0, p1, callback );
}

Your DWR program If all goes well, that's all right, count you lucky; If you encounter a remote method that throws an exception while processing your request, you will see that DWR will only give you an alert ("Error") that is simply wrong, and that is not enough. So you need to figure out how to proactively capture this bug and show it to the user in a more friendly way. So if you encounter a remote call to the exception, you are also lucky, because you can think to learn one.

The alert ("error") is actually a DWR global error handling that can be changed by Dwr.engine.setErrorHandler (ErrorHandler) to its default behavior, such as

function Errh (errorstring, exception) {
alert ("Prompts you for a custom global error message.) ");
}

Dwr.engine.setErrorHandler (ERRH);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.