1 title:: 22_Runtime_errors
2 summary:: Mark Polishook tutorial
3 categories:: Tutorials>Mark_Polishook_tutorial
4 related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial
6 section::Runtime errors
8 Runtime errors occur while a program is executing.
10 section::Common errors
13 ## an object receives a message which it doesn't understand
14 ## a binary operation (addition, subtraction, multiplication, etc.) can't be performed
15 ## a value other than true or false appears in a conditional (boolean) test
16 ## a file can't be opened (a primitive fails)
19 section::Object doesn't understand
27 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
30 ERROR: Message 'createRuntimeError' not understood.
34 Instance of Array { (057E7560, gc=01, fmt=01, flg=11, set=00)
38 DoesNotUnderstandError-reportError
39 arg this = <instance of DoesNotUnderstandError>
42 arg error = <instance of DoesNotUnderstandError>
44 arg this = <instance of DoesNotUnderstandError>
45 Object-doesNotUnderstand
47 arg selector = 'createRuntimeError'
49 < closed FunctionDef > (no arguments or variables)
50 Interpreter-interpretPrintCmdLine
51 arg this = <instance of Interpreter>
53 var func = <instance of Function>
54 Process-interpretPrintCmdLine
55 arg this = <instance of Main>
58 ////////////////////////////////////////////////////////////////////////////////////////////////////
60 The ERROR section explains what went wrong. The RECEIVER section names the 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
63 Process-interpretPrintCmdLine
69 Interpreter-interpretPrintCmdLine
75 Object-doesNotUnderstand
93 DoesNotUnderstandError-reportError
96 which is the first line in the stack.
98 ////////////////////////////////////////////////////////////////////////////////////////////////////
101 DoesNotUnderstandError-reportError
104 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).
106 ////////////////////////////////////////////////////////////////////////////////////////////////////
114 to create another runtime error message.
116 ////////////////////////////////////////////////////////////////////////////////////////////////////
118 The ERROR, RECEIVER, ARGS, and CALL STACK headers in the post window explain the problem: Instances of class Char have no knowledge of multiplication.
121 ERROR: Message '*' not understood.
125 Instance of Array { (067F5470, gc=C4, fmt=01, flg=00, set=01)
130 DoesNotUnderstandError-reportError
131 arg this = <instance of DoesNotUnderstandError>
134 arg error = <instance of DoesNotUnderstandError>
136 arg this = <instance of DoesNotUnderstandError>
137 Object-doesNotUnderstand
141 < closed FunctionDef > (no arguments or variables)
142 Interpreter-interpretPrintCmdLine
143 arg this = <instance of Interpreter>
145 var func = <instance of Function>
146 Process-interpretPrintCmdLine
147 arg this = <instance of Main>
150 section::Unitialized variable (binary operation fails)
152 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 unitialized data) will create a runtime error.
156 var a = 10; // a is declared and initialized
157 var b; // b declared but not initialized, so it defaults to nil
164 { i.postln } // print the value of i if it doesn't equal 3
165 { (a * b).postln }; // when i equals 3, do a * b
166 // ... which is a problem if b is nil
176 ////////////////////////////////////////////////////////////////////////////////////////////////////
178 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.
180 ////////////////////////////////////////////////////////////////////////////////////////////////////
187 ERROR: binary operator '*' failed.
191 Instance of Array { (067D92B0, gc=CC, fmt=01, flg=00, set=01)
197 DoesNotUnderstandError-reportError
198 arg this = <instance of BinaryOpFailureError>
201 arg error = <instance of BinaryOpFailureError>
203 arg this = <instance of BinaryOpFailureError>
204 Object-performBinaryOpOnSomething
213 < FunctionDef in closed FunctionDef >
218 arg function = <instance of Function>
220 < FunctionDef in closed FunctionDef > (no arguments or variables)
222 arg this = <instance of Routine>
223 arg inval = 758.000000
226 ////////////////////////////////////////////////////////////////////////////////////////////////////
228 section::True, false, or other
230 A value other than true or false in a boolean test, as in
233 if(x=4) { "this is ok"};
239 ERROR: Non Boolean in test.
243 MethodError-reportError
244 arg this = <instance of MustBeBooleanError>
247 arg error = <instance of MustBeBooleanError>
249 arg this = <instance of MustBeBooleanError>
252 < closed FunctionDef > (no arguments or variables)
253 Interpreter-interpretPrintCmdLine
254 arg this = <instance of Interpreter>
256 var func = <instance of Function>
257 Process-interpretPrintCmdLine
258 arg this = <instance of Main>
261 ////////////////////////////////////////////////////////////////////////////////////////////////////
263 Correcting the test clause fixes the problem.
266 if(x==4) { "this is ok"};
269 ////////////////////////////////////////////////////////////////////////////////////////////////////
271 section::Primitive fails
273 Asking for the length of a non-existent file creates a runtime error. The notification shows what went wrong (a C code primitive failed).
276 f = File("i_don't_exist", "r");
279 ERROR: Primitive '_FileLength' failed.
282 Instance of File { (067D9970, gc=C4, fmt=00, flg=00, set=01)
283 instance variables [1]
287 MethodError-reportError
288 arg this = <instance of PrimitiveFailedError>
291 arg error = <instance of PrimitiveFailedError>
293 arg this = <instance of PrimitiveFailedError>
294 Object-primitiveFailed
295 arg this = <instance of File>
297 arg this = <instance of File>
298 < closed FunctionDef > (no arguments or variables)
299 Interpreter-interpretPrintCmdLine
300 arg this = <instance of Interpreter>
302 var func = <instance of Function>
303 Process-interpretPrintCmdLine
304 arg this = <instance of Main>
307 ////////////////////////////////////////////////////////////////////////////////////////////////////