Node js Try Catch

JavaScript's try-catch-finally statement works very similarly to the try-catch-finally in C++ and Java.

try {
    throw new Error();
} catch(e) {
    console.log(e); // [Error]

e in this example is the exception value.


try {
  throw "thrown error message";
  console.log("this message will never be shown!");
catch (e) {
  console.log(e); //Catch error message thrown
finally {
  console.log("it's finally block"); // It's always get executed


thrown error message

it's finally block