Error Handling

Both of the callback controls support client side error handling that is enabled through an error callback handler. When a callback is made to the server, you assign an Error callback handler that is called whenever an error occurs as part of the callback or the client code that is firing and/or handling the callback.

Remember that all callbacks are asynchronous so the errors too are fired asynchronously even if an error occurs in the client code before it calls back on the server. All callback handlers are simlpy functions that are called with a single result object parameter which is a CallbackException object which contains a message property. The handler looks like this:

function OnPageError(Exception) { alert(Exception.message); }

If you have multiple callbacks you can route all of them to the same error handler, or if you need specific error handling you can route to a specific error handler that performs custom operations. The latter might be necessary if at the start of the callback you disable or hide controls and they need to be made visible again when the call completes.

The error handling hook up is easy, but it varies slightly depending on which mechanism you use.

wwHoverPanel:

The error handler is hooked as part of the Control.startCallback() function:

function ShowPanel() { LookupPanel.startCallback(event,"id=" + Id.toString(),null,OnError); } function OnError(Exception) { alert(Exception.message); }

wwMethodCallback:

For method callbacks you pass the error handler as part of the proxy method call or - if you are explicitly using the client callback object - on the wwCallbackMethod object's callMethod() function.

function GetCustomerEntity() { CustomerCallback.GetCustomerEntity($('txtCustomerId').value,GetCustomerEntity_Callback,OnPageError); } function GetCustomerEntity_Callback(Result) { ... } function OnPageError(Exception) { alert(Exception.message); }

If you're explicitly using the wwCallbackMethod object the code looks like this:

var ExceptionCallback = Callback_GetCallback(); ExceptionCallback.postbackMode = "Post"; // pass form vars to server ExceptionCallback.callMethod('ThrowException',[$("txtSaySomething").value], ThrowException_Callback,OnPageError);

wwHttp Client Object

The more low level wwHTTP object also uses a callback error handler in the same fashion and it too fires an error handler when an error occurs.

Http = new wwHttp(); var Result = Http.send("http://localhost/default.asp",null,TestCallback,OnError); function HttpCallback(Result) { $("divResult").innerHTML = Result; } function OnError(Exception) { alert(Exception.message); }

Control Error Handling

The various client controls don't have any specific error handling functionality, especially in regards to the initial control assignment. wwControl, wwList and wwToolTip take control IDs or instance variables as input and if those instances are not set the controls may fail on subsequent calls.

You can check the isNull property to ensure the control was properly created:

var Ctl = new wwControl("divMessage"); if (Ctl.isNull) return; Ctl.fadeout();

Note that you can't check Ctl == null directly because the control instance gets created no matter what once you use the new keyword to construct the object.


  Last Updated: 9/17/2006 | © West Wind Technologies, 2008