Function to test if custom attribute exists

I am looking for a function that I can use in a dynamic component to test if a custom attribute exist.

I have 2 components A and B. Both components hold a component X.
On component A I have created a custom attribute TotalLength. On component B this does not exists.

What I would like to create is a custom attribute on component X that does something like this:
TotalLength = If(Exists(Parent!TotalLength),Parent!TotalLength,LenX)

Is there a workaround in sketchup to obtain this behaviour?

There is no way that I can find to trap the non-existence of an attribute (or any error for that matter.)

An excellent idea for a new DC function.