Declare it, always, when the form or kiosk asks about food. That single habit is the difference between a routine inspection and a fine. Arrival cards and electronic declarations in most countries include a food or agricultural products question, and answering yes to a bag of sweets costs you nothing except possibly a two-minute bag check. In strict biosecurity countries, officers mostly wave through declared packaged goods and confiscate only genuinely risky items, with no penalty attached to an honest declaration.
Failing to declare flips all of that. Undetected, nothing happens; detected, and detection is likely where X-rays and dogs screen arriving bags, you face on-the-spot fines that dwarf the value of the food, potential higher penalties for repeat or deliberate cases, and a flag on your record inviting future searches.
When unsure whether your item counts as food, declare anyway and let the officer decide. The declaration is about honesty, not about whether the item is ultimately allowed, and officers everywhere treat those as very different tests.