asserterror

A keyword that can be used in Scripting, to test whether an expected erroe message is indeed generated.

Examples

asserterror Unknown variable
a = 2 * b + 3

The line a = 2 * b + 3 contains the unknown variable b. Therefore, the script would normally issue an error message like

Unknown variable:
« a = 2 * b

Script line 2 not performed or completed:
« a = 2 * b + 3 »
Menu command “Run” not completed.

The line with asserterror prevents the error message from being popped up, and instead checks that the error message contains the string “Unknown variable”, which it does.

This one works differently:

b = 4
asserterror Unknown variable
a = 2 * b + 3

In this case the expected error message does not occur, and the script exits with the following error message:

Script assertion fails in line 2: error « Unknown variable » not raised.
Instead: no error.

Script line 3 not performed or completed:
« a = 2 * b + 3 »
Menu command “Run” not completed.

Another case:

asserterror What is blabla
a = Create Sound from blabla: 1, 2, 3

In this case a different error message than the expected error message occurs, and the script exits with the following error message:

Script assertion fails in line 1: error « What is blabla » not raised.
Instead: Command “Create Sound from blabla:” not available for current selection.

Script line 2 not performed or completed:
« a = Create Sound from blabla: 1, 2, 3 »
Menu command “Run” not completed.

Links to this page


© Paul Boersma 2023