5.6 Mixing Callbacks and Errbacks

The preceding examples of callback chain operation dealt exclusively with either callback or errback propagation. In practise it is possible that an onCallback method within the callback chain may throw an Exception or an onErrback method within the callback chain may successfully resolve an error condition, allowing normal processing to resume.

The processing of return values and exception conditions for onCallback and onErrback methods is actually identical. If an onCallback or onErrback method returns normally, the next deferrable callback handler in the chain will always have its onCallback method executed - passing in the data object returned by the previous stage of the callback chain. Similarly, if an onCallback or onErrback method throws an exception, this will be caught and passed to the onErrback method of the next deferrable callback handler in the chain.

Listing 5.13 demonstrates the way in which error conditions which are not dealt with by the terminal deferrable will appear in the reactor logs. In order to prevent these warnings, neither the onCallback or onErrback method of a terminal deferrable should throw an exception - these will usually return a null object reference since no further processing is possible.