Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Error in promise catch does not trigger global error handler

Why does an error thrown in a promise reject/catch method not trigger the global error handler? How can a global error handler that includes these be created? In my app the global error handler logs the error.

function doPromise() {
    return Promise.reject()
}

window.addEventListener('error', function (e) { console.log('Global handler ' + e.message) })

doPromise()
 .then()
 .catch(e => {
    console.log('Promise catch')
    throw new Error('Promise catch error')  // Does not trigger global error handler
  })
    
throw new Error('Core error')  // To prove global error handler is working
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

This is not an error, but Unhandled Rejection:

The unhandledrejection event is sent to the global scope of a script when a JavaScript Promise that has no rejection handler is rejected

Working version of the code:

function doPromise() {
    return Promise.reject()
}

window.addEventListener('error', function(e) {
    console.log('Global handler ' + e.message)
})
window.addEventListener('unhandledrejection', event=>{
    console.log('Unhandled rejection', event)
}
);

doPromise().then().catch(e=>{
    console.log('Promise catch')
    throw new Error('Promise catch error')
    // Does not trigger global error handler
}
)

throw new Error('Core error')
// To prove global error handler is working
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!