5.5 Deferred Error Callback Chaining

The process of handling exception conditions within a callback chain is similar to conventional callback chaining. Error conditions are passed up the callback chain by throwing exceptions from within the deferrable callback handler's onErrback method, as shown in Listing 5.12.


\begin{listing}
% latex2html id marker 1255\begin{small}
\begin{verbatim}pub...
...\end{verbatim}
\end{small}\caption{Simple Chained Errback Handler}
\end{listing}

On calling the onErrback method on a given deferrable callback handler, the deferred event object passes the exception condition which was thrown by the previous stage in the callback chain. In the example implementation the exception is simply re-thrown at each stage. Generally speaking, the error condition should always be dealt with by the terminal deferrable, since unhandled error conditions at this position in the callback chain will effectively be `lost'. Listing 5.13 demonstrates the way in which such unhandled error conditions are reported to the reactor log as warning messages. The full code for this example is included in the deferred examples package as DeferredChainExample2.


\begin{listing}
% latex2html id marker 1267\begin{small}
\begin{verbatim}INF...
...im}
\end{small}\caption{Output of Simple Deferrable Errback Chain}
\end{listing}