This brings back memories. :-)

If it was just frustration, we would ask if he needed help or gently provide suggestions, but not take over. If frustration morphed into what we called a "loop", which meant he spun into an obsessive tizzy from which no learning or personal recovery was possible, we tried to distract and if it failed removed him from the situation. (The loop was often a result of needing food or sleep also.). We would definitely distract if we thought a loop was likely.

If it was a safety issue, he got one warning and then either a time out for him of 1 minute per year of age or removal of offending item for usually rest of day.

If he threw something, he lost it immediately for an hour or more.

It worked like a charm for us. At 18 months, we would take a deep breath and count to 10 but he could not say his numbers at 12 months.

Edit: ...and when out of sight I ate tons of chocolate on some days... Still do...