Three examples:
Protection Fighting Style's trigger is when a valid target "is attacked"; you must decide when the attack is declared; this means that you decide before the attack is rolled, and thus before you know whether it would be a hit or not.
Uncanny Dodge is triggered when you "are hit"; you decide when an attack hits you; this means that you do not have to use it before the attack is rolled, and so you cannot waste it on an attack that would miss anyway, but you must decide when the hit is confirmed, before the damage is rolled.
Misty Escape (Warlock fey pact feature) is triggered when you "take damage"; you decide to use it once you take damage - after the attack is declared, after it is rolled and the hit confirmed, and after the damage is rolled.
Yay! I finaly understand some rule corectly!

^_^