Skip to content

' Signal

Signal an error

Syntax: 'x, '[x]

where x is a symbol atom or string, aborts evaluation and passes x to the interpreter as a string.

q)0N!0;'`err;0N!1
0
'err

The only way to detect a signal is to use Trap.

q)f:{@[{'x};x;{"trap:",x}]}
q)f`err
"trap:err"

Trap always receives a string regardless of the type of x.

Restrictions

q)f 1         / signals a type error indicating ' will not signal a number
"trap:stype"
q)f"a"        /q will not signal a char
"trap:stype"

Using an undefined word signals the word as an error:

q)'word
'word

which is indistinguishable from

q)word
'word

Error-trap modes

At any point during execution, the behaviour of signal (') is determined by the internal error-trap mode:

mode behavior
0 abort execution (set by trap @ or .)
1 suspend execution and run the debugger
2 collect stack trace and abort (set by .Q.trp)

During abort, the stack is unwound up to the nearest trap (@ or . or .Q.trp). The error-trap mode is always initially set to

  • 1 for console input
  • 0 for sync message processing

\e sets the mode applied before async and HTTP callbacks run. Thus, \e 1 will cause the relevant handlers to break into the debugger, while \e 2 will dump the backtrace either to the server console (for async), or into the socket (for HTTP).

q)\e 2
q)'type             / incoming async msg signals 'type
  [2]  f@:{x*y}
            ^
  [1]  f:{{x*y}[x;3#x]}
          ^
  [0]  f `a
       ^
q)\e 1
q)'type             
  [2]  f@:{x*y}
            ^
q))                 / the server is suspended in a debug session

Trap, Trap At
Basics: Control, Debugging, Error handling