What you are referring to is the SCV Halt command (hot key T). By issuing this command you can regain control of your scv and issue a movement command (moving it to safety) without canceling the building. Another SCV can then be right clicked onto the building to finish it.