Backbencher.dev

JS Daily 31 - Optional Catch Binding

Last updated on 21 Dec, 2020

What is the output of following code?

try {
  throw new Error();
} catch {
  console.log("Error thrown");
}
----o----

The output is "Error thrown".

Now it is ok to omit the parameter part of catch. But it is good to have the error parameter and at least log it in the console.

try {
  throw new Error("Some Error");
} catch (err) {
  console.log(err.message);
}
--- ○ ---
Joby Joseph
Web Architect