pantry moth problems?

A while ago I was talking with my friend who had to throw away a bunch of food because moths had gotten in her pantry. If I remember correctly, she actually had to throw away things twice because some eggs stayed behind the first time.

I've had this happen once before and it's extremely frustrating! I saw this thing online, it is called a pantry moth trap. I haven't used them, but I thought I'd share the link with anyone who might be having or have had moth problems. Replacing all your food due to moths is expensive, so these would probably be worth it! I'm not quite sure how moths get in your pantry to begin with, but it's frustrating!