These are mistakes I've made in real games and what I learned from them. Wiki Gardeners: If these might go better on another page, feel free to move them or note the canonical location of these mistakes.
This is a tricky play. The tempting response to a hane at the edge is to play over it, at the marked spot. Unfortunately, in this situation those two black stones above ...
... are White's shoe-horn into stealing more territory. If Black responds at , then White has a double-atari to make.
White threatens the marked stones and forces black to cover, . White breaks though with .
Not covering at is much worse.
You'll lose a few more points of territory, but it's the best way out.
The lesson to learn is that two stones alone are much weaker than they seem. One stone away from the edge is tight enough to not have this problem and three stones has enough liberties to survive, but two is a cause of trouble.
Alex Weldon: You're missing one variation that is probably the most important, since it's the least obvious to beginners: