You must bring your bike to a stop... NOW!
There is a technique to panic stopping. And it's best to learn the skills and practice some of its finer points before life calls on you to use it for real.
A Lesson In Physics
First, some physics. Consider the relative stopping power of your front and rear brakes. Lock up your rear brake and your wheel will generally skid. Lock up your front brake and what usually happens? I've never seen it skid, though some have told me it can. But I will expect your bike to stop dead in its tracks and you to pivot over the handlebars!
So which brake does the better job of stopping the bike? I hope you said front brake.
And now to a second point about relative steering control of your bike. When a wheel locks up, you've lost basic steering control with that wheel. That's why cars have anti-lock brakes (ABS). They're designed to keep the wheels braking, but still rolling, so the driver can have a chance to steer the car while it's slowing down. It doesn't help him stop faster, but it lets him maybe steer clear of an obstacle while at the same time slowing down.
The same principles are at work on your bike - I'm talking about the laws of physics here and you'll find them working everywhere in life.
Next, there are a couple more principles to remember when you've got to panic stop:
Principle #1 - A Feathered Touch For Your Own ABS
This doesn't mean a light touch. But it also doesn't mean grabbing your brake levers with fists full of fingers. Brake levers are, well as the word says, levers. (More physics here folks.) They've been designed to apply leverage to your braking system. You should be able to use just one or two fingers to squeeze them with enough force, whether you're riding with your hands on the hoods, or down in the drops. And using just a couple of fingers lets the rest of your hand work some solid steering, giving you a chance of avoiding the obstacle that just popped into your line.
Another element to feathering is the technique of modulating your squeezing force. With a little practice, your fingers can work almost as well as a car's ABS, and you should be able to brake hard enough to slow your wheels, but not so hard that you lock up your wheels.
Principle #2 - A Stopping Bike Really Wants To Keep Going In A Straight Line
Once you've got those brakes on, your bike will start to stand straight, and want to keep going in a straight line from the point where you started to squeeze the brakes. As I just said above, with one or two fingers actually squeezing the levers, you will have more hand available to otherwise steer the bike, but understand, this will be extremely difficult. Perhaps if you've feathered just enough power into the brakes to slow you down, you can then release them completely, in which case you can dive your bike out of the way. And if that means riding over into the ditch, that's a far better outcome than riding straight into the side of the SUV that just pulled out.
But I think most of us will just need to do our best to stop in a straight line. Here are a few drills to practice, so you aren't too surprised about what to do in real life. I'd suggest finding a smooth. level, grassy field. A golf green would be ideal, but I think the course marshals might not agree with me...
Get a little speed going, and use the power of leverage with two fingers on your brake levers.
Apply the rear brake harder than the front. Make the rear wheel lock-up and skid. Then feather it so the wheel doesn't skid.
Next, use your front brake more than the rear. Notice how the front brake will slow you more than the rear brake. If you are adventurous and have your helmet and gloves on (I hope you do!), try to actually lock up the front wheel and see if you can just get the rear wheel to pop off the ground. Hey, it's a grassy surface, so if you fall over it won't be so bad!
What you should notice is how your body wants to keep moving forward, and your front wheel tries to dig down into the grass.
It's time to learn the full technique. You'll be applying both brakes, and simultaneously trying to push your body backwards, low and away from your front wheel.
Stay on the grass, but now increase your speed. Put your hands in the drops, with index and middle fingers on the brake levers. Bend your elbows. You need to be able to push yourself backwards, but if your arms are already straight, you'll have nothing left to push with.
Now, at speed, set your pedals horizontal, apply both brakes in a feathering fashion and abruptly use your hands and feet to push yourself backwards, off the back of your seat, and stay low. You might even drop your butt down and behind your seat (careful, you could get stuck there!). If you skid your back tire, that's fine. But do your best to avoid going over the handlebars.
Do it again, with your hands up on the hoods. And again in the drops. And again on the hoods. And again... you get the picture.
Here's a modulating technique that I think works well: consider a one-two punch of the front brake followed by the rear brake. A quick on-off feather action on the front brake will scrub some of your speed quickly, followed by more speed scrubbing with the rear brake, but with little further chance of locking up your front wheel and sending you flying over the handlebars.
No more grass.
After you've done Drill #2, and have a really good feel for the technique, you need to feel how it works on the pavement. Use an empty parking lot, or a paved bike path, and run through Drill #2 again. A few rear wheel skids are okay, but too much and you're going to ruin your tire.
Finally, when you're out on a regular ride, occasionally try out your new panic stopping technique at an ordinary stop sign or red light. You don't need to skid your tire, but keep familiar with the feathering, modulating technique of applying force to your brake levers while at the same time straightening your arms and pushing your body low and backwards.
I hope the technique of panic stopping becomes second nature, so if you ever need it, the skill pops out of you faster than the unexpected obstacle that just popped up in front of you!