I hate being pregnant for exactly this reason; I know it sounds crazy, but even though I've never had particularly difficult pregnancies the thought of being pregnant gives me over-the-top anxiety. I had two miscarriages before conceiving DD1, and then hemorrhaged throughout her pregnancy. I was absolutely convinced she was going to die in utero, and coped with it the way PPs have said; just didn't let myself get attached at all. With DD2's pregnancy, even though it was a textbook pregnancy I just couldn't let myself get attached until she was born, and even after she was born I remember feeling completely detached, asking the doctor if everything was ok with the baby. I don't necessarily think it's healthy/good to be so detached, but that's the only way I could cope.
I would say the most helpful thing is to find people (either IRL or online) who know where you're coming from, and will be supportive rather than make you feel like a terrible person for having those feelings. People would always tell me that it was going to be alright, and I hated that; it's not always alright, and sometimes it's just awful and terrible. But if you have support around you, even in the worst case you *will* pull through.
That said, most of the time babies do turn out just fine, otherwise there wouldn't be so many people in the world!