A GFCI works by making sure that amperage is equal at all times between the hot and neutral sides of the circuit. If this is ever not true, power is "leaking" from the circuit because of a short to ground, either "safely" through an appliance's metal shell to the ground leg of the outlet, or unsafely through you to something else that's earthed like metal plumbing.
A GFCI thus detects MOST situations in which you can be shocked, and will kill the circuit. You will still feel a shock, but it shouldn't be permanently damaging or fatal.
A GFCI will NOT protect you in situations where the current can flow from hot to neutral through you, and so there's no current lost. You can, for instance, get a rough shock by touching a frayed, ungrounded appliance cord (like from a toaster) and contact both sides of the circuit. Unless you're doing this underwater or are also holding your metal sink, there will be little or no "leakage" to earth, and so the GFCI may take longer to register a fault or may not even trip at all.
AFCI breakers (Arc Fault Circuit Interrupters) are one better in certain respects. Instead of simply making sure AHot == ANeutral, they look for patterns of voltage spikes or variance that indicate electrical arcing is occurring. This means that if you were to touch a frayed lamp cord, the high variance in resistance of your skin will cause those patterns and trip the breaker. However, AFCIs are subject to "false positives"; they will trip if you, for instance, plug a vacuum cleaner that is already turned on into an outlet on an AFCI breaker. Other appliances with heavy-duty motors can cause similar false trips. As such they are mainly required only in bedrooms, where electrical arcing can cause a fire right in that room which will be a deadly danger to you long before the smoke alarm in the hall outside goes off.