as I know node js is single threaded, so if I write
throw new Error()
somewhere in method, it should kill the current thread, so will shut down the whole process?
Reading the NodeJs documentation about exceptions helps you understand quite easily what happens.
On the section Error Propagation and Interception you can read the following:
Node.js supports several mechanisms for propagating and handling errors that occur while an application is running. How these errors are reported and handled depends entirely on the type of Error and the style of the API that is called.
And answering to your question:
Any use of the JavaScript throw mechanism will raise an exception that must be handled using try / catch or the Node.js process will exit immediately.
So basically any unhandled exception will kill the whole node process.
That's where tools like PM2 kick in, restarting your node application whenever that happens.
Although this is from 2012 I think it's a nice article and quite simple to understand what should you do with uncaught exceptions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With