Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bugs181
Copy link

@bugs181 bugs181 commented Nov 18, 2024

Without catching the promise chain HERE, even with proper user-land exception handling, there is no way to catch errors. This results in an uncaught exception that crashes node.

See here for more info: Uncaught Exception, even with Try Catch

Example:

process.on("uncaughtException", uncaughtExceptionListener)

start().catch(console.error)

async function start() {
  try {
    await queue.connect()
  } catch (err) {
    return console.error('Some Error:', err.message)
  }
}

// queue.connect in class
async function connect() {
  try {
    // The next line is where the error originates
    await client.connect()
    return console.log('Never makes it here')
  } catch (err) {
    // Never makes it here either
    return console.error('[client] Connection failed!')
  }
}

Output:

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^

Error: connect ECONNREFUSED 127.0.0.1:6090

The result is that the entire user application crashes, with no way to recover.

Without catching the promise chain HERE, even with proper user-land exception handling, there is no way to properly catch it. This results in an uncaught exception that crashes node.

See here for more info: (Uncaught Exception, even with Try Catch)[https://stackoverflow.com/questions/79200499/uncaught-exception-even-with-try-catch]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant