Since you only provided general information and not things like when it happens (examples) here is some basic information that might help. If this dosen't cover please provide details:
* Overstimulation. You're petting your cat and suddenly he grabs you with his claws and teeth. Not a full-powered attack, but you've still got those sharp tips around your hand. What to do? In the short run, freeze. Don't fight your cat or you may trigger a real bite. Sometimes smacking your other hand hard against a hard surface - a table top, for example - may startle your cat into breaking off. If you stay still, however, he usually calms down and releases you.
That's the solution if you've gotten to the attack
stage. The better option is to be familiar with your cat and his body language and stop petting before he becomes overstimulated. Cat lovers often think such attacks come without warning, but the fact is that they missed the warning signs of a cat who has simply had enough. The tail is the key: If your cat starts twitching his tail in a jerky fashion, time to call off the petting has arrived. Build slowly.
Often these "I've had enough" attacks come if you've been petting your cat's belly. This is a very sensitive area for cats, and even if yours offers it to you, you're better off petting somewhere else. One reason is sexual in nature: Your male cat becomes aroused when his belly is rubbed, and reacts with a bite because that's what feline mating behavior involves.
* Play aggression. Sure, it hurts all the same, but the cat who pounces on your feet/hands and then careens off the wall isn't trying to hurt you - he's playing. You need to increase your play sessions with your cat with an appropriate toy, such as a cat fishing pole or toy on a string - not one of your body parts - to help your cat
burn off his excess energy before you try for a quiet pet session. Let him know that attacks on you are not permitted by letting him have it with a blast from an air horn or a spray bottle. A little Bitter Apple on your hand can help, too.