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.
function ShowPanel() { LookupPanel.startCallback(event,"id=" + Id.toString(),null,OnError); } function OnError(Exception) { alert(Exception.message); }
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);
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); }
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.