Click or drag to resize

Error Handling

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.

C#
try
{
   // ... - some FIXAntenna.Net API calls
}
catch(ApplicationException ex)
{
    Console.WriteLine("EXCEPTION: " + ex.Message);
}
VB
Try
    ' ... - some FIXAntenna.Net API calls
Catch exception1 As ApplicationException
    Console.WriteLine(("EXCEPTION: " & exception1.Message))
End Try
C++
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)

C#
        // 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);
VB
        ' FixEngine's events Listener 
Private Class EngineEventsListener
    ' Methods
    Public Sub OnError(ByVal sender As Object, ByVal e As FixEngine.ErrorArgs)
        Console.WriteLine(("OnError: " & e.Error.ToString))
    End Sub
    Public Sub OnNotification(ByVal sender As Object, ByVal notification As FixEngine.NotificationArgs)
        Console.WriteLine(("OnNotification: " & notification.Notification.ToString))
        Console.WriteLine(("Notification's type: " & notification.Notification.GetType.ToString))
        If (TypeOf notification.Notification Is SessionNotification) Then
            Dim notification1 As SessionNotification = CType(notification.Notification, SessionNotification)
            Console.WriteLine(("Session's Notification, SenderCompID=" & notification1.SenderCompID & ", TargetCompID=" & notification1.TargetCompID))
        End If
    End Sub
    Public Sub OnWarning(ByVal sender As Object, ByVal e As FixEngine.WarningArgs)
        Console.WriteLine(("OnWarning: " & e.Warning.ToString))
    End Sub
End Class

Dim engine_listener As New EngineEventsListener
' register for the events
AddHandler FixEngine.Instance.Notification, New FixEngine.NotificationHandler(AddressOf engine_listener.OnNotification)
AddHandler FixEngine.Instance.Warning, New FixEngine.WarningHandler(AddressOf engine_listener.OnWarning)
AddHandler FixEngine.Instance.Error, New FixEngine.ErrorHandler(AddressOf engine_listener.OnError)
C++
        // FixEngine's events Listener 
ref class EngineEventsListener
{
public:
    void OnNotification(Object^ sender, FixEngine::NotificationArgs^ notification)
    {
        Console::WriteLine("OnNotification: {0}", notification->Notification);
        Console::WriteLine("Notification's type: {0}", notification->Notification->GetType());

        if(SessionNotification::typeid->IsInstanceOfType( notification->Notification ) )
        {
            SessionNotification^ sn = static_cast<SessionNotification^>( notification->Notification );
            Console::WriteLine("Session's Notification, SenderCompID= {0}, TargetCompID={1}", sn->SenderCompID, sn->TargetCompID);                
        }
    }

    void OnWarning(Object^ sender, FixEngine::WarningArgs^ e)
    {
        Console::WriteLine("OnWarning: {0}", e->Warning);                
    }

    void OnError(Object^ sender, FixEngine::ErrorArgs^ e)
    {
        Console::WriteLine("OnError: {0}", e->Error);
    }  
};


EngineEventsListener^ engine_listener = gcnew EngineEventsListener();

// register for the events
FixEngine::Instance->Notification += gcnew FixEngine::NotificationHandler(engine_listener, &EngineEventsListener::OnNotification);
FixEngine::Instance->Warning += gcnew FixEngine::WarningHandler(engine_listener, &EngineEventsListener::OnWarning);
FixEngine::Instance->Error += gcnew FixEngine::ErrorHandler(engine_listener, &EngineEventsListener::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.