KScript docs
EN

Debugging

Pausing on errors

When a script throws an error, the debugger pauses where it was thrown, before anything catches it, with every function the error came through still on the Call Stack. The message shows in the editor, under the line, and the Variables view shows what each variable held when it went wrong:

<fn name="share" params="total: number, people: int">
  <if $people == 0>
    <throw type="Validation">There is nobody to share {$total} between.</throw>
  </if>
  <return value="$total / $people" />
</fn>

<let name="each" value="@share(30, people: 0)" />
<echo value="$each" />
fn share(total: number, people: int) {
  if $people == 0 {
    throw Validation "There is nobody to share {$total} between."
  }
  return $total / $people
}

$each = @share(30, people: 0)
echo $each

Here the debugger pauses on line 3, inside share(), where Locals shows $people = 0. Continue lets the error go on: a catch that handles it runs as usual, and an error nothing catches ends the script, with its message in the Debug Console.

A script that throws and catches errors on purpose pauses each time. Untick Errors in the Breakpoints view to stop pausing on them.