Sometimes a good brisk walk will help. If you have stayed out a good 15-20 minutes and can't stay longer and have to bring the dog in, you must watch the dog while he is in the house, crate the dog, or keep the dog in some type of pen or enclosure. A young dog may have to go every half an hour or so. Control the dog's food and water so that he is fed and watered at certain times and then taken outdoors immediately. Anger or punishment for unwanted behavior is counterproductive.
Anger has no place in working with dogs.
Anger will only make things worse. Tell yourself that you will work with the dog without anger, and that you will not allow yourself to get angry. Your anger can be controlled and your dog and you will both be happier. When something does make you angry, walk away and come back when you are calm. Decide that the next time the event happens you will deal with it without anger.