M
M
Mariik2017-03-28 21:59:44
Node.js
Mariik, 2017-03-28 21:59:44

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 options
throw 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);
});

They don't work, even though they should have.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kustikov, 2017-04-10
@art1z

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 question

Ask a Question

731 491 924 answers to any question