Sign in

Libre University uses your GitHub account. Signing in is only needed to sit a final test, so the score is kept on your profile.

Errors and exceptions

1.[3p]

What does a stack trace tell you?

Correct
The answer is: Where the program stopped and the chain of calls that led there, which is not necessarily where the mistake is
The answer is: Where the program stopped and the chain of calls that led there, which is not necessarily where the mistake is
The answer is: Where the program stopped and the chain of calls that led there, which is not necessarily where the mistake is

2.[3p]

Match each error kind to what causes it.

  • ReferenceError

  • TypeError

  • RangeError

  • SyntaxError

  • text that is not a valid program, including malformed JSON

  • a name that does not exist, usually a typo

  • a value outside an allowed range, or a recursion with no reachable base case

  • a value that is not the kind the operation needs

Show the answer

ReferenceError: a name that does not exist, usually a typo TypeError: a value that is not the kind the operation needs RangeError: a value outside an allowed range, or a recursion with no reachable base case SyntaxError: text that is not a valid program, including malformed JSON

3.[3p]

Put the frames of a stack trace in the order they are printed, from top to bottom.

  1. The function that called the one that failed

  2. The function where execution stopped

  3. The top level line that started everything

Show the answer

c, a, b

4.[3p]

Why is catch (err) { } with an empty body worse than not catching at all?

Correct
The answer is: A crash names the failure, points at a line and stops before the damage spreads, and swallowing it destroys all three
The answer is: A crash names the failure, points at a line and stops before the damage spreads, and swallowing it destroys all three
The answer is: A crash names the failure, points at a line and stops before the damage spreads, and swallowing it destroys all three

5.[2p]

finally runs even when the try block exits through a return.

Correct
The answer is: True

6.[2p]

throw "oops" is legal. Why throw new Error("oops") instead?

Correct
The answer is: An `Error` object carries a name, a message and a stack, and a bare string carries none of them
The answer is: An `Error` object carries a name, a message and a stack, and a bare string carries none of them
The answer is: An `Error` object carries a name, a message and a stack, and a bare string carries none of them

7.[3p]

Which of these are reasons to validate input at the edge of a program rather than in every function?

Select all that apply

Correct
Correct
Correct
The answer is: The checks that remain are few enough to be worth reading, The failure is reported at the point the bad data arrived, Values inside the program can then be trusted

8.[2p]

Which grade of wrongness produces no message of any kind? Write one word.

CorrectNot quite: logic

9.[2p]

A syntax error is reported at line 60, but the file looks correct there. Where is the mistake most likely to be?

Correct
The answer is: Above line 60, where an unclosed brace or quote left everything after it parseable
The answer is: Above line 60, where an unclosed brace or quote left everything after it parseable
The answer is: Above line 60, where an unclosed brace or quote left everything after it parseable