To prevent this from happening, it's important to always double-check the connections before starting the jump. Make sure that the positive terminal of the good battery is connected to the positive terminal of the dead battery, and that the negative terminal of the good battery is connected to a metal part on the frame of the dead vehicle (not the negative terminal of the battery).
If you do accidentally connect the positive and negative terminals, immediately disconnect the jumper cables and do not attempt to start the vehicles. Allow both batteries to cool down for at least 30 minutes before attempting to jump the vehicle again.