catch Block

noun

say it: “KACH blok” /kætʃ blɑk/

The part after a try block, written catch (error) { }, that runs only when code in the try block throws an error, and receives that error.

What is catch Block in JavaScript?

catch Block — A block that handles a matching exception from its try block.

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

In a sentence

  • “The catch block showed Sorry, that recipe file is damaged, instead of letting the program crash.”
  • “The catch block showed "We couldn't load the menu. Try again?" instead of a blank page.”
  • “I logged error.message in the catch block to see why the order failed.”

Level: Journeyman · More JavaScript terms at this level

Updated

In other subjects