Exam Written Response - Run-Time Error - Year 23-24

One of the sample questions for the AP Exams says, "Describe a change to your procedure that will result in a run-time error. Explain why this change will result in a run-time error. "

What are some examples of run-time errors? Is a syntax error a run-time error?

Thank you so much for your help,

One example of a run time error is trying to divide by 0 or accessing an element of a list at an index that is out of bounds.


Thank you so much. That is useful. But do you know if a syntax error is also a run-time error? How do you define run-time error? I have read about it online, but I would like to hear from a reliable source. :slightly_smiling_face:

A syntax error is not a run time error. Syntax errors are like typos, when the interpreter or compiler cannot understand the command. For example, ver I = 0 is a syntax error, because var is misspelled. Another example of a syntax error is when you forget to close a brace in a for loop

For (var I = 0; I < 10; I++) {

This structure has two syntax errors - for is with an uppercase F and no closing brace.

A run time error occurs when the computer doesn’t know what how to run a command. For example, the computer does not know how to divide by 0 or how to access an element at a negative index.

I hope this helps.


It does help. Thank you again!

Looking for run-time errors - Do these count?

Here I have some questions again. I am wondering if the following errors count as run-time errors or not. The first two start as “syntax” errors, I guess, but you only realize they “exist” when running the app.

1) Quote Maker App

If the variable fontFamily is not assigned any value when being created, as soon as the user starts typing, the console shows an error message.

correct: var fontFamily = " ";
incorrect: var fontFamily;

2) Outfit Picker App

The onEvent for the left button is written:

if(topsIndex > 0){
topsIndex = topsIndex - 1;

If instead, we do not include the conditional statement, the console will show an error when we continue to click the left button and we have no more items on index -1, -2, etc of the list.

Incorrect code:
topsIndex = topsIndex - 1;

The console shows:

3) Cereal Nutrition App
When the user selects any category and then, after that, selects “Pick a Category” from the mostDropdown or the leastDropdown, the console indicates that the user is trying to get a column called “Pick a Category” from a table called “Cereal Nutrition”, but that column doesn’t exist.

This is the screenshot.

Thank you for your help,

A. Rossignoli

1 Like

I would say yes, these are all examples of runtime errors!

I would also argue that your first two are actually not syntax errors - they are valid javascript statements and will not break the program on their own.

In your first example, fontfamily could be left empty, and if the programmer accounts for this later (perhaps setting a default font in a particular case later in the program) then the error would never happen. But because there is something wrong with the logic - ie. trying to use a value that doesn’t exist - we get a runtime error when we try to complete that action.


Thank you, Madeline. Yes, I understand what you say and I agree with you. I love it. Now I can show some concrete examples to my students.

Thanks for posting these examples. I found the Quote maker in Unit 4 Lesson 11 and the Outfit picker in Unit 6 Lesson 2 but can’t seem to put my finger on the Cereal Nutrition app. Do you happen to recall where it is in the curriculum?

I am also looking for examples to show my students for the sample AP questions. This is a tough one for us when they are looking at the functions they created.

I would love to see Code.org incorporate more about run time errors in the future.

Hi @bridget_dycus,

That would be an excellent feature request to submit. That is the best place to put those to make sure the correct folks at Code.org see them!

Michael K.

1 Like