Concept
Decide where errors are caught and what callers get: thrown exceptions for bugs and unexpected failures, returned results for failures the caller is expected to handle. Mixing the two makes both unreliable.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Error handling patterns doing its job.
type Result<T> = { ok: true; value: T } | { ok: false; error: string };
function parsePort(text: string): Result<number> {
const n = Number(text);
if (!Number.isInteger(n) || n < 1 || n > 65535) {
return { ok: false, error: "port must be 1-65535, got " + text };
}
return { ok: true, value: n };
}
const port = parsePort(process.env.PORT ?? "");
if (!port.ok) throw new Error(port.error);Catching an error only to log it and carry on. The caller then works with a half-finished state and the real failure shows up later somewhere unrelated.
Your roadmap puts these before Error handling patterns, unless you already know them.
Once a session shows you understand Error handling patterns, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Error handling patterns.