Optionally getting a string from a topic

My Topic has this association:
{
“childTypeUri”: “com.climbo.poc.route.gradeFrench”,
“childCardinalityUri”: “dmx.core.one”
},
Which is formerly declared as this topic type:
{
“value”: “Grade (French)”,
“uri”: “com.climbo.poc.route.gradeFrench”,
“dataTypeUri”: “dmx.core.text”
},

Now it can happen that topic of the first type do not set a value for gradeFrench. This causes a problem when I want to read such data using this code:
topic.getChildTopics().getString(“com.climbo.poc.route.gradeFrench”, null)

Instead of returning null when the value is not available I get an exception telling me that the type “com.climbo.poc.route.gradeFrench” is not in the outer topic. Well, this is correct but I was hoping to avoid an exception by using a function which allows setting a default value for this case. In DM4 this was possible with a getStringOrNull() method.

Am I missing something here?

Your reasoning is perfectly valid: the ChildTopics getters which take a defaultValue do not throw if no child topic exists. But they still throw if you pass an invalid CompDefURI.

Most likely your problem is a spelling error in com.climbo.poc.route.gradeFrench. If topic's type definition does not have a CompDef with that URI an exception is thrown. Note that in this case the CompDefURIs listed in the exception are those existing in the parent type definition (not those existing at instance level).

Possibly the DMX error messages should be improved.

Additionally, when specifying a CompDefURI keep in mind the special format in case the CompDef involves a Custom Assoc Type – childTypeUri#customAssocTypeUri – just the same as in DM4. But in your situation this is not the case though.