3 ms·
If primitives fail, they raise a signal. There is also a primitive for unconditionally raising a signal. Most flavors of K have a primitive called "error trap"
by RodgerTheGreat 7y ago
If primitives fail, they raise a signal. There is also a primitive for unconditionally raising a signal. Most flavors of K have a primitive called "error trap" which captures signals emitted by a function application, should they occur:
f:{11 22 33 x}
.[f;,1;:]
0 22
.[f;,4;:]
(1;"index")
If a signal is not trapped, K pauses execution and opens the debugger, where a user may interactively inspect the environment, evaluate code, and resume:
f 4
index error
{11 22 33 x}
^
> x
4
>
Overall not that different from try...catch in a garden-variety interpreted language with a REPL.
- i_don_t_know 7y agoThanks! That's fairly straightforward and, I guess, avoids having to pass a closure.