{11::¯1 ⋄ 2÷0}⍬
¯1
{11::¯1 ⋄ ⎕SIGNAL 11}⍬
DOMAIN ERROR
Why is the first signal caught, while the second is not?
As per the documentation for ⎕SIGNAL
(my emphasis):
The state indicator is cut back to exit from the function or operator containing the line that invoked
⎕SIGNAL
, or is cut back to exit the Execute (⍎
) expression that invoked⎕SIGNAL
. If executed within a nested dfn, the state indicator is cut back to exit from the capsule containing the line that invoked⎕SIGNAL
. An error is then generated.
In other words, by the time ⎕SIGNAL
is done doing its thing, we're already outside the dfn and thus the dfn's error guard (::
) is not in effect any more.
To work around this, you have to use ⎕SIGNAL
in a separate capsule. For example, you can define a cover function outside the function where you want to use it:
Signal←{⎕SIGNAL ⍵}
{11::¯1 ⋄ Signal 11}⍬
¯1
Alternatively, you can put ⎕SIGNAL
in its own execution capsule:
{11::¯1 ⋄ ⍎'⎕SIGNAL 11'}⍬
¯1