I like to whenever I need one to prevent an enemy from killing me in one little combo. And some are just good in certain lane match-ups. So like if you're an AP mid vs a Zed, highly consider a Zhonya's unless you think you can live even without it. Or if you're an AD top vs an AP, you can consider Maw but I wouldn't get it if you can get ahead enough to just kill them faster than they can kill you. But if you're somewhat behind it can be a great item. And when the laning phase is over, consider if there's any fed enemy that can just instakill you if you don't build any defensive items. If there is, it's likely a good idea to build some, unless you think there's some way you can stay effective while dodging that enemy.
But really, there's no magic guide for how you can figure out what to build easily. You really have to just get good at the game and be able to tell how fights are going to play out and use that information to tell what is going to help out the most in that fight. And even that can be deviated from if you happen to have just the right amount of gold to buy something that's almost as good.