Their question is already on this topic.
Node.js Best Practice Exception Handling
which is old and the answers are very outdated, domains haven't even been outdated since.
Now, in the Async / Await Node.js script, you should not consider similar cases synchronously and asynchronously, as well as exclude exceptions from synchronization functions and reject promises in asynchronous functions instead of returning the Error instance to the previous case.
let divideSync = function(x,y) { // if error condition? if ( y === 0 ) { // "throw" the error throw new Error("Can't divide by zero exception") } else { // no error occured, continue on return x/y } }
Simulate async deactivation operation
let divideAsync = function(x, y) { return new Promise(function(resolve, reject) { setTimeout(function() {
Thus, synchronous and asynchronous exceptions can be handled uniformly.
let main = async function () { try {
source share