0

I have an async function like this:

async function testFunction() {
    await doSomeWork();

    const sshClient = new SSHClient();
    sshClient.on('error', async error => {
        throw error;
    });
    sshClient.connect();
}

And Im using it like this:

testFunction().then(() => {
    // when an error happens in sshClient I end up here
}).catch(error => {
    // and not here
});

Is there a way to catch an error which is thrown in a nested async function?

  • 1
    Does your `sshClient` have an event when the connection *succeeds* as well? – CertainPerformance Aug 27 '18 at 22:45
  • Possible duplicate of [Asynchronous exception handling with bluebird promises](https://stackoverflow.com/questions/25143476/asynchronous-exception-handling-with-bluebird-promises) – GGG Aug 27 '18 at 22:49

0 Answers0