4 ms·
How does error handling work in K? For example, what happens when you try to read a file that doesn’t exist? How does the read function indicate failure to the
by i_don_t_know 7y ago
How does error handling work in K? For example, what happens when you try to read a file that doesn’t exist? How does the read function indicate failure to the caller? How does the caller check and recover (show an error to the user and continue with some default values)?
- RodgerTheGreat 7y agoIf 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.