🔰rethrow

rethrows an unexpected error.

try {
    functionThatThrows();
} catch (err) {
    if (err instanceof InputError) { ... } 
    else { throw err }                        // ⭐️ rethrow
}
// custom Error
class InputError extends Error {}

// function that may throw
function functionThatThrows() {
    // ...
    throw new InputError("Invalid input");
}

try {
    functionThatThrows();
} catch (err) {
    if (err instanceof InputError) { ... } 
    else { throw err }                        // ⭐️ rethrow
}

Last updated