One of those situations happened in the Turkish 1st league some seasons ago:
How would you decide in a) this concrete situation and b) if this specific type of offence was not made by a defending player, but the defending team's goalkeeper?
a) Penalty Kick & Yellow Card
In this concrete situation, the correct answer is: Penalty Kick & Yellow Card. Hitting the ball with a thrown object (boot, shinguard, etc.) is regarded as handling the ball in the Laws of the Game. As deliberately handling the ball requires a direct free-kick or a penalty kick (inside the penalty area), this also counts here.
b) Indirect Free-Kick & Yellow Card
The goalkeeper is allowed to take the ball with his hands in his own penalty area and can therefore not be penalized for deliberately handling the ball by throwing an object. However, throwing an object at the ball is clearly unsporting and must be dealt with appropriately: A yellow card must be issued and an indirect free-kick should be given.