A thrown error moves up the active synchronous call stack until a catch handler intercepts it or the runtime reports it as uncaught. Calls above the throw site stop executing, so recovery depends on where a handler appears. section 7.5
function level3() {
throw new Error("Origin point");
}
function level2() {
level3(); #A
console.log("Never executed");
}
function level1() {
level2(); #A
console.log("Never executed");
}
level1(); #BTrace the failure from level3 through level2 and level1 to observe how unwinding skips statements after the failing call. section 7.5
Handlers can recover locally, clean up, or add context before rethrowing. A transaction handler can roll back and throw a new error with the original error as its cause, preserving both operational context and the underlying failure. section 7.5
Avoid the propagation traps that make failures harder to recover or diagnose:
- Treat finally as part of the propagation path: returning from it suppresses a pending error, while throwing from it replaces the original error. section 7.5
- Use throw, try, and catch for exceptional conditions rather than implementing ordinary branching with exceptions; use return, break, or continue for control flow. section 7.5
- Do not expect a surrounding synchronous try block to catch an error thrown later by setTimeout; asynchronous scheduling breaks the original call stack. section 7.5
- Uncaught asynchronous failures require host-specific handling, such as browser error and unhandledrejection events or Node.js uncaughtException and unhandledRejection events. section 7.5
A cleanup block can erase the failure
A function that throws inside try but returns from finally produces the return value instead of propagating the error. A finally block that throws a second error propagates the second error instead, leaving the original failure unavailable to ordinary recovery.




