Checking to see if a Public transform is (missing)

Hello everyone, I have 2 prefabs (prefab1 and prefab2); prefab1 has a script which checks prefab2’s transform realtime when it spawns. However, When I delete prefab2; I need the script in prefab one to check to see if prefab2 transform is deleted (missing). I tried this:

public Transform prefab2;

void Update(); {
if(prefab2 != null){
//what the script does if prefab2 is missing;
}

}

But it did not work, Here is my error:

MissingReferenceException: The object of type ‘Transform’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

How can you check to see if a public transform is missing? (c#) - (In the inspector its seen as “Transform (Missing)”) Thanks!

You could use a try/catch which would return the state but avoid the exception

try{
   if(prefab2){ 
      // prefab2 is 
   }  
}catch(Exception){
   // No prefab2 
}