Question: If we’re not allowed to throw food then how can we throw sweets at a chassan at his aufruf?
Answer: Rambam (Berachos 7:9) and the Shulchan Aruch (OC 171:1) write that one must treat food in a respectful manner. R’ Yehoshua Neuwirth (Shemiras Shabbos Kehilchasa 20:29) writes that this even applies to food that one isn’t allowed to eat, such as chametz on Pesach.
The Gemara (Berachos 50b) writes that as bread is more important than other food, one should never throw bread. Other food, however, may be thrown providing that it won’t get ruined (Rambam, Berachos 7:9; Magen Avraham OC 171:1; Aruch Hashulchan OC 171:3; Mishna Berura 170:9).
Thus, the Magen Avraham (OC 167:38) writes that when one says hamotzi on behalf of others, he must pass the bread to them rather than throw it (See Mishna Berura 167:88).
The Gemara (ibid) writes that people used to throw nuts towards the chassan and kalla.
Nowadays, people typically throw sweets or small bags of food at a chassan when he gets his aliya on his Shabbos aufruf. While this almost universal custom has no real mekor, Sefer Taamei Haminhagim (940) explains the significance behind many of the foods that people throw. Additionally, it is not assur and adds to the excitement for many. The Kaf Hachaim (OC 171:26) and Mishna Berura (171:21) write that those who do so should not throw soft sweets that will get ruined.The poskim (Magen Avraham OC 171:1; Aruch Hashulchan OC 171:5) write that one who sees food on the floor must pick it up. Additionally, one must ensure that one does so to enhance the simcha and one isn’t mevazeh the kedusha of the shul.