Najova

DocsGuides

Mistakes

Najova finds mistakes in two places: when it reads a script, and while it runs. Each message says the file, the line and what to change.

Mistakes found when reading

Typos, a missing ], or a block without its end line. Najova lists them all and runs nothing.

shop.naja
$let[price;5]
$if[$get[price] > 3]
  $print[Too dear]
najova check shop.naja
shop.naja:2: The $if on line 2 has no $endif.

Mistakes found while running

Some mistakes only show up with real values, such as maths on something that isn't a number. The script stops there.

total.naja
$let[basket;$list[3;4]]
$print[Total: $sum[$item[$get[basket];1];$item[$get[basket];2]]]
$print[$item[$get[basket];3] + 1]
najova run total.naja
Total: 7
total.naja:3: Cannot do nil + number (maths needs numbers).

Catch a mistake with $try

Put lines that might fail in $try. If one fails, the script goes on at $catch, and the message is in the name you give it.

safe.naja
$function[parseAge;typed]
  $let[age;$number[$get[typed]]]
  $if[$get[age] == nil]
    $error[“$get[typed]” isn't a number]
  $endif
  $return[$get[age]]
$endfunction

$try
  $print[Age: $parseAge[29]]
  $print[Age: $parseAge[twenty]]
$catch[why]
  $print[Please try again: $get[why]]
$endtry
najova run safe.naja
Age: 29
Please try again: “twenty” isn't a number
$error makes your own mistake, with your own message.