5.3 Deferred Error Handling

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.


\begin{listing}
% latex2html id marker 1189\begin{small}
\begin{verbatim}pub...
...batim}
\end{small}\caption{Simple Long Running Task With Errbacks}
\end{listing}

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.


\begin{listing}
% latex2html id marker 1204\begin{small}
\begin{verbatim}pub...
...nd{small}\caption{Simple Deferrable Callback Handler With Errback}
\end{listing}