First if you're using the MPlug version, it cannot fail but if you're using the MObject version and if it fails, it would return an empty MDataHandle. I.e. equivalent to:
MDataHandle tmp ;
and its type() method should return you kInvalid. Unfortunately, if the child attribute is also a compound attribute, type() would also return kInvalid.
So what's up? in order to keep MDataHandle operations fast in Maya, minimal checking is performed, which for most methods means no checking at all. It is up to the caller to ensure that the method being called and the parameters passed to it are all appropriate for the handle. For the child() methods that means that attribute to which the handle currently points is compound and the attribute passed to the method really is one of its children. So you can ensure success by checking for those two conditions before making the call
More generally, if you want to access attribute data with error checking, use an MPlug.
Comments
You can follow this conversation by subscribing to the comment feed for this post.