Node Process Manager

Node.js try catch - Error Handling


Free Online Tutorials on JavaScript, Node.js, React.js, PHP, JAVA, Python, HTML, GraphQl, TypeScript, MEAN, MERN Stack, etc.

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