Summary of DWR Exception Handling

Source: Internet
Author: User

The script engine. js contains the core part of DWR. Generally, your application should include it.
Util. JS is usually included, which contains some optional practical methods.
Demo. JS is dynamically defined in DWR. It also contains a corresponding remote version called demo. java. If you see
The following code:
Demo. Method1 = function {callback, P0}
Demo. method2 = function {callback}
So we can see that the first parameter is the callback function, and P0 is probably the parameter you want to return.

Common Methods in engine. js include:
Dwrengine. seterrorhandler (function) handle errors
Dwrengine. setwarninghandler (function) handle warnings
Dwrengine. setTimeout () sets the timeout time.

Because "A" in Ajax refers to asynchronous (asynchronous), every demo. Method execution is asynchronous.
If you want to specify global timeout settings, you can use dwrengine. setTimeout () to complete

Similarly, dwrengine. seterrorhandler (function), dwrengine. setwarninghandler (function)
Used to set global error and warning handling

Of course, if you want to handle a function timeout, warning, or error
As follows:
Demo. Method (Params ,{
Callback: function (data) {alert ("It worked ");},
Errorhandler: function (Message) {alert ("It broke ");},
Timeout: 1000
});

DWR can capture custom error exceptions such as: Implemented in errdemo. Java
Public class errdemo {
Public String getdata (){
Throw new nullpointerexception ("message ");
}
}

Call in customer segment
Function EH (MSG) {// Error Function
Alert (MSG );
}

Dwrengine. seterrorhandler (EH );
Errdemo. getdata (function (data) {alert ("123 ");});
The result of the program is that eh jumps out of the dialog box. At this time, MSG is quite called.
Exception. getmessage () method value

This is also acceptable if you want to capture custom exceptions.
Public class errdemo {
Public String getdata (){
Date when = new date (); // funkyexception extend exception
Throw new funkyexception ("message", when );
// Implement getwhen () method in funkyexception
}
}

Client
Function EH (MSG, ex ){
Alert (MSG + ", date =" + ex. When );
}

Dwrengine. seterrorhandler (EH );

Errdemo. getdata (function (data) {alert ("123 ");});
The displayed dialog box contains "message, date = mon Jan 01 2008 10:00:00 GMT + 0100"

 

 

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.