try Block

noun

say it: “TRY blok” /traɪ blɑk/

The part of a try statement, written try { }, that holds code which might fail, so a failure goes to the catch block instead of stopping the program.

What is try Block in JavaScript?

try Block — A block containing code that may throw an exception.

function reserve(seats) {
    if (seats < 1) {
        throw new Error("Seat count must be positive");
    }
}

In a sentence

  • “I put JSON.parse inside a try block because the saved text might be broken.”
  • “I put the await fetch line inside a try block so a lost connection wouldn't crash the page.”
  • “Everything in the try block after the failing line was skipped.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects