question

Upvotes
Accepted
154 18 24 35

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
icon clock
10 |1500

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

This is a seeded question.

Upvotes
Accepted
78.8k 250 52 74

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);
                }
icon clock
10 |1500

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

Upvotes
1.2k 23 31 44

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.

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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