Error HandlingFIX Antenna .NET Programmer's Guide

In FixAntenna.NET library errors are handled in 2 possible ways:

This topic contains the following sections.

Critical Exceptions, Raised Like Usual .NET Exceptions.

Critical exceptions are .NET exceptions that usually happen when FixAntenna.NET cannot be started normally or unforeseen reasons that do not allow FixAntenna to operate properly.

When a critical error is encountered, the FIXAntenna.Net API throws an exception, which is usually an instance of the ApplicationException class or a class, derived from ApplicationException.

Such exceptions can be caught in your .NET applications, as usual with try {} catch {} block.

try
{
   // ... - some FIXAntenna.Net API calls
}
catch(ApplicationException ex)
{
    Console.WriteLine("EXCEPTION: " + ex.Message);
}

Most often, critical exceptions happen during engine start-up or initialization code when:

  • FixAntenna Configuration could not be found
  • Files or Folders referred to in FixAntenna Configuration, (for example Logs folder, license file, etc.) do not physically exist or cannot be accessed.
  • An attempt to use any methods or create any classes is made before FixEngine is properly initialized
  • Several instances of FixEngine use the same Listen ports
  • A physical TCP/IP Connection between 2 applications cannot be established because of weak throughput, firewalls or when the 2nd application was not started while the 1st application expects it to be.

This list is not complete so one need to examine Exception details (sometimes, details of the InnerException too) in order to understand the reason of the exception.

Make sure that you dispose all unneeded Disposable objects in the final {} block, so even when an exception is thrown, you will release all resources. For example, you need to dispose com.b2bits.FIXAntennaSession objects.

If you decide that application needs to be stopped as a result of critical exception, do not forget to call FixEngineStop during application exit code.

Non-Critical Errors, Warnings and Messages, Delivered via Event Subscription Mechanism

Non-critical errors are usually logical or operation errors that FixAntenna can survive.

FixAntenna normally logs all errors, warning etc., according to the settings of Log.* parameters in FixAntenna Configuration

However, you can implement your own logging logic or any specific business logic.

To monitor engine notifications, warnings and error messages, register for the corresponding engine event (FixEngine. Notification, FixEngine.Warning, or FixEngine.Error)

        // FixEngine's events Listener 
class EngineEventsListener
{
    public void OnNotification(Object sender, FixEngine.NotificationArgs notification)
    {
        Console.WriteLine("OnNotification: " + notification.Notification);
        Console.WriteLine("Notification's type: " + notification.Notification.GetType());

        SessionNotification sn  = notification.Notification as SessionNotification;
        if(null != sn)
        {
            Console.WriteLine("Session's Notification, SenderCompID=" + sn.SenderCompID + ", TargetCompID=" + sn.TargetCompID);                
        }
    }

    public void OnWarning(Object sender, FixEngine.WarningArgs e)
    {
        Console.WriteLine("OnWarning: " + e.Warning);                
    }

    public void OnError(Object sender, FixEngine.ErrorArgs e)
    {
        Console.WriteLine("OnError: " + e.Error);                
    }  
};

EngineEventsListener engine_listener = new EngineEventsListener();

// register for the events
FixEngine.Instance.Notification += new FixEngine.NotificationHandler(engine_listener.OnNotification);
FixEngine.Instance.Warning += new FixEngine.WarningHandler(engine_listener.OnWarning);
FixEngine.Instance.Error += new FixEngine.ErrorHandler(engine_listener.OnError);

Make sure that you dispose all unneeded Disposable objects in the final {} block, so even when an exception is thrown, you will release all resources. For example, you need to dispose com.b2bits.FIXAntennaSession objects.

If you decide that application needs to be stopped as a result of critical exception, do not forget to call FixEngineStop during application exit code.