The use of deferred event callbacks may be used to pass back the results of long running tasks on successful completion. However, another mechanism is required for dealing with error and exception conditions which may occur during execution. This is provided through the use of errbacks, or errored callbacks.
In order to demonstrate the use of errbacks, the long running task example given in Listing 5.4 may be extended as shown in Listing 5.7. This shows a typical case where any exceptions generated during the long running task are caught and passed back via the deferred event object's errback method. As an alternative to using try/catch, new exceptions may also be explicitly created as the errback parameter.
Errors are processed by deferrable callback handler using the onErrback method. In place of the generically typed data parameter which is passed on callbacks, the onErrback method accepts a parameter of type Exception, which is the exception object passed by the deferred errback call. An example of a simple deferrable callback handler with support for error processing is shown in Listing 5.8. The full code for this example is included in the deferred examples package as DeferredEventExample2.