Use a finally block to run cleanup after try-catch processing, whether an error was thrown, caught, or not thrown. It provides a cleanup point for operations such as a transaction, where cleanup belongs at the boundary of the whole operation. section 7.5 section 7.5
A return or throw inside finally can suppress or replace an error already in flight. The original error may still exist, but its recovery and debugging context is lost. Avoid using finally to return values or throw new errors carelessly. section 7.5 section 7.6
function suppressed() {
try {
throw new Error("This disappears");
} finally {
return "Success!"; #A
}
}
function replaced() {
try {
throw new Error("This disappears");
} finally {
throw new Error("This replaces it");
}
}
console.log(suppressed()); #B
console.log(replaced()); #CCompare a finally block that returns over a pending error with one that throws a replacement error. section 7.5



