In the following code
// file: main.js
class A {
async start() {
throw 'error';
}
}
module.exports = A;
// file index.js
var r = require('./main.js');
let v = new r();
try {
v.start();
} catch (e) {
console.error(e);
}
I am new to Javascript and Node.js, Node.js throws UnhandledPromiseRejection when I am clearly catching the exception, why does it happen ?
This error originated either by throwing inside of an async function without a catch block
To see the reason:
node –trace-warnings index.js