awesome-everything RU
↑ Back to the climb

Base CS from zero

When a program fails: multiple-choice review

Crux Multiple-choice synthesis across the failure unit: error vs exception, stack unwinding, reading a trace, undefined behaviour, and debugging as reasoning.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 13 min

Six questions that cut across the whole unit. Each one is a small judgement call you make in front of a real failure — not a definition to recite, but a distinction to hold steady: condition versus mechanism, loud versus silent, reasoning versus guessing.

Goal

Confirm you can connect the four lessons into one picture: an error is a condition, an exception is the mechanism that unwinds the stack, the stack trace is the snapshot of that unwind, undefined behaviour is the dangerous silent case, and debugging is reasoning over a deterministic machine.

Quiz

A program tries to open a file that does not exist. Which of these is the error, and which is the exception?

Quiz

main calls a, a calls b, b raises an exception. Only main has a handler. How many frames does the runtime pop, and where does normal control flow resume?

Quiz

A four-line stack trace reads (top to bottom): divide, getAge, loadUser, main. A new engineer fixes main first. Why is that the wrong instinct?

Quiz

One program reads index 5 of a 3-element array and raises an 'index out of range' exception. Another reads the same out-of-range cell and returns whatever bits are there, with no error. Which is the more dangerous failure, and why?

Quiz

In JavaScript, reading index 9 of a 3-element array gives undefined (not a crash), and then your code computes undefined + 1. What happens, and why does it resemble undefined behaviour even though each step is defined?

Quiz

A program returns a wrong total. An engineer starts flipping comparisons and re-running until the number looks right. What is the principled objection, grounded in how the machine works?

Recap

The unit is one chain: an error is the condition, an exception is the mechanism that stops normal flow and unwinds the call stack frame by frame looking for a handler, and the stack trace is that stack frozen at the throw — read top-down, throw site first. Undefined behaviour is the dangerous case where no error is raised at all and a garbage value travels silently. And because the machine is deterministic, the response to any failure is reasoning, not guessing: form a testable hypothesis, narrow the range, read the trace, check state, then fix the step you have proven is wrong.

Continue the climb ↑When a program fails: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.