22_Runtime_errors:
Filter:
Tutorials/Mark_Polishook_tutorial | Tutorials > Mark_Polishook_tutorial

22_Runtime_errors

Mark Polishook tutorial

Runtime errors

Runtime errors occur while a program is executing.

Common errors

  1. an object receives a message which it doesn't understand
  2. a binary operation (addition, subtraction, multiplication, etc.) can't be performed
  3. a value other than true or false appears in a conditional (boolean) test
  4. a file can't be opened (a primitive fails)

Object doesn't understand

In the case of

SuperCollider prints a four-part error notification to the post window. The parts of the notification are ERROR, RECEIVER, ARGS, and CALL STACK, as in

////////////////////////////////////////////////////////////////////////////////////////////////////

The ERROR section explains what went wrong. The RECEIVER section names the class of the object to which the message was sent. The ARGS section says how many arguments were included in the message. Read the CALL STACK from the bottom to the top to see where the error happened. Reading from bottom to top means going from

to

to

to

to

to

which is the first line in the stack.

////////////////////////////////////////////////////////////////////////////////////////////////////

is the mechanism that prints the error notification to the post window. Select it and press cmd-j to see how it works (how it prints the notification).

////////////////////////////////////////////////////////////////////////////////////////////////////

Execute

to create another runtime error message.

////////////////////////////////////////////////////////////////////////////////////////////////////

The ERROR, RECEIVER, ARGS, and CALL STACK headers in the post window explain the problem: Instances of class Char have no knowledge of multiplication.

Uninitialized variable (binary operation fails)

Here, the variable a is initialized to an integer and the variable b isn't initialized. Multiplying a (the integer 10) by b (nil, the value that SuperCollider uses for uninitialized data) will create a runtime error.

////////////////////////////////////////////////////////////////////////////////////////////////////

The printout shows the code ran successfully until the index, i, reached 3, which is when a * b happened. The ERROR, RECEIVER, ARGS, and CALL STACK headers describe the problem.

////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////

True, false, or other

A value other than true or false in a boolean test, as in

produces

////////////////////////////////////////////////////////////////////////////////////////////////////

Correcting the test clause fixes the problem.

////////////////////////////////////////////////////////////////////////////////////////////////////

Primitive fails

Asking for the length of a non-existent file creates a runtime error. The notification shows what went wrong (a C code primitive failed).

////////////////////////////////////////////////////////////////////////////////////////////////////