This could be a primary respiratory problem like an infection, chronic bronchitis, allergies, cancer, kennel cough, or a collapsed trachea, or it could be cardiogenic. Cardiac causes include heartworm disease and chronic heart failure. Any of these causes if left untreated can lead to serious complications and permanent damage. The next step is to go to your vet to investigate the problem. Your vet will take a thorough history of the problem, ask some specific questions about the nature and the character of the cough and most likely take some chest xrays to visualise the lungs and heart.
The is probably just having trouble breathing or something, when my dog is excited he'll often throw up. So it might be something similar. The dog could also have something in it's mouth or he just forgets to breathe and swallows too much spit causing him to choke. I'd try to keep him from getting too excited. It could also be old age unless he's young.
First are you sure your pup doesn't have a collapsed trachea or other problem? Sounds like maybe a reverse sneeze. There are videos in the link.
www.petplace.com
www.petplace.com