If both targets are illegal when Grave Exchange tries to resolve, it won’t resolve and none of its effects will happen. If only one target is legal, the effect relevant to that target will happen and the other will not.