Chemical pregnancy???

What causes a chemical pregnancy? Is there a way to prevent them from happening?