Answer the question
In order to leave comments, you need to log in
How to catch errors correctly in Node.js?
Hello.
How to catch globally in a node (we basically don’t know where the error will be. try / catch is not suitable) an error that was thrown with the throw keyword
Type optionsthrow new Error("Bad Error");
process.on("uncaughtException",(err)=>{
console.log("******** Error ***********");
console.log(err.message);
});
process.on("uncaughtError",(err)=>{
console.log("******** Error ***********");
console.log(err.message);
});
Answer the question
In order to leave comments, you need to log in
process.on("uncaughtException", ....)
It works exactly ( https://nodejs.org/api/process.html#process_event_... it's just that in this method all you can do is write it to the log, or send a message to the admin that everything is bad. Nothing can be sent to the client
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question