Only the API support team can answer that Jana!
To me, it looks like the .Name swallows any exceptions and returns "" if an exceptions occurs. Evidently, all components must have a name so you can assume if that the return is an empty string that there's something wrong that your component object.
Off the top of my head, best approach is to construct a tree class of SelectionDataString strings and component2 objects that includes a method to validate. This will preserve the structure of the components tree even if after you replace a component. You can try to select the said component with its SelectionDataString (from the tree class, not from the object), if the selection's return is false then something's wrong. You can then delete the component2 object and refresh the tree.
you can use AssemblyDoc.GetComponents(false) after replacing the component. It will give you latest info for components.
Or could you please elaborate the application workflow?
'subLvlComp-1' is the second element of the component array 'IAssemblyDoc.GetComponents(false)' retrieved before replacing the top level component 'topLvlComp-1' but after replacement of the top level component, the child component is not in the final assembly and this is why .Name2 of the component 'subLvlComp-1' is " " because it cannot access that component. It should throw an error when you try to use IComponent2.Name2 property, but some reason it doesn't.
You need to use IAssemblyDoc.GetComponents(false) method again as explained by Raghvendra Bhargava to get the latest array of components, once you delete, add or replace any component. You could use 'GOTO' to jump back to 'swComps = swAssy.GetComponents(False)' in your macro every time one of the these happens to make sure that you get the latest component array.
Amen Allah Jlili has mentioned one work around. Other option if to use 'IComponent2.Select4'. It will return 'False' if the component is not selected.
Hope this helps.
Component2.GetID() returns -1 if the component is invalid. But it also returns -1 for the root component. So I guess I will just stick with the Name2 == "" check (the root component has a name other than "").