2
      {11::¯1 ⋄ 2÷0}⍬
¯1
      {11::¯1 ⋄ ⎕SIGNAL 11}⍬
DOMAIN ERROR

Why is the first signal caught, while the second is not?

Adám
  • 6,573
  • 20
  • 37
Tobia
  • 17,856
  • 6
  • 74
  • 93

1 Answers1

1

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
Adám
  • 6,573
  • 20
  • 37