forwardHandler Events   Table of ContentUnderstanding Handler Statesforward
Error Handling and Recovering

The Handler uses exceptions to report error conditions. For example, the Handler will raise an exception to report about inability to connect to the multicast feed server or about the failure in logon procedure. However, once subscribing to market data is succeeded, the Handler is not able to report about any further errors since it performs all handling asynchronously on a background. For this reason, the Handler exposes ErrorOccurred event to be able to subscribe to errors and handle them.

Getting notified about Errors

The Handler fires the ErrorOccurred event each time an error occurs. The ErrorEventHandler delegates whose signature is used by the event. It has a couple of input parameters which define a code (identifier) of the error and a human-readable explanation or description of the error. The ErrorCode enumeration contains constants for the errors which may occur while processing market data from multicast feed.

Recovering from Errors

An important aspect of the Handler behavior is that there is nothing special required to handle common error conditions. In particular, once the subscription for market data is successfully started, the Handler will process incoming market data and handle all failures by itself without any additional actions. That means, there is no need to restart the subscription for market data manually, the Handler will do everything itself. Also, the Handler performs recovering from errors in the optimal way. For example, in the case of network-related issues, the Handler will rebuild only those books and market states which are based on market data from the problematic multicast feed channel. It will not invalidate and rebuild the entire subscription.

Example

The following sample demonstrates how to receive notifications about errors occurred in the Handler.

C#
class ErrorDumper
{
    public ErrorDumper()
    {
    }

    public void AttachTo(Handler handler)
    {
        handler.ErrorOccurred += OnError;
    }

    public void DetachFrom(Handler handler)
    {
        handler.ErrorOccurred -= OnError;
    }

    private void OnError(object sender, ErrorEventArgs args)
    {
        Console.WriteLine(
            "Error occurred while executing handler: {0}",
            args);
    }
}