I would consider your first case as a parsing error. That is, the parser is trying to do a permanent folding (pre-calculate the value) and errors at this point, because it receives a division by a zero exception. Other syntax errors behave the same way, i.e. Do not start the trap:
trap { "Got it!" } 1/;
You must provide a value expression on the right-hand side of the '/' operator.
If you change the code to this:
$denom = 0
trap { "Got it!" } 1/$denom
Got it!
Attempted to divide by zero.
Then the trap is triggered, because the parser can no longer precompress the value.
source
share