question

Catherine Wong avatar image
154 13 18 30

Does RFA.NET have methods that don't throw exceptions when a field definition is not found?

RDMFieldDictionary.GetFidDef(fid) throws exceptions when a field definition is not found. I would like to get interfaces that will not thrown exeptions when a field definition is not found.

treprfarfa-api.netexception
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jirapongse avatar image
45.2k 103 43 60

You can implement your own extension methods, such as RDMFieldDictionary.TryGetFidDef() interfaces.

using ThomsonReuters.RFA.RDM;
using ThomsonReuters.RFA.Common;
namespace RDMFieldDictExtension
{
    public static class RDMFieldDictExtension
    {
        public static RDMFidDef TryGetFidDef(this RDMFieldDictionary dict, short fieldId, out RFA_String error)
        {
            RDMFidDef fidDef = null;
            error = new RFA_String();
            try
            {
                fidDef = dict.GetFidDef(fieldId);                
            }catch (InvalidUsageException ex)
            {
                error.Set(ex.Status.StatusText.ToString());
                return null;
            }
            error.Set("Success");
            return fidDef;
        }
        public static RDMFidDef TryGetFidDef(this RDMFieldDictionary dict, RFA_String fieldName, out RFA_String error)
        {
            RDMFidDef fidDef = null;
            error = new RFA_String();
            try
            {
                fidDef = dict.GetFidDef(fieldName);
            }
            catch (InvalidUsageException ex)
            {
                error.Set(ex.Status.StatusText.ToString());
                return null;
            }
            error.Set("Success");
            return fidDef;
        }
    }
}

The sample usage is:

using RDMFieldDictExtension; 
…
…
                RFA_String error;
                currentFidDef = rdmFieldDict.TryGetFidDef(new RFA_String("UNKNOW_FIELD"), out error);
                if(currentFidDef == null)
                {
                    System.Console.WriteLine("Error: " + error.ToString());
                }
                else
                {
                    System.Console.WriteLine(currentFidDef.LongName);
                }
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Steven McCoy avatar image
1.2k 23 28 42

This would have to be done manually, for example iterate through getMinNegField() to getMaxFieldId() and create your own lookup tree.

Long term this is not an issue with the Elektron SDK which will eventually have a .NET native release. Using ETA/C from .NET does not throw exceptions, using EMA/C++ completely hides the dictionary so it is no longer a concern.

10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.