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

195
Views
Why error is not bubbled up if it's coming inside a promise without its catch block?

ok i'm asking this again, why the catch in the following code is not working as expected ? is this a design flaw of js ?

const getUserById = (id, authorized) => {
    return new Promise((resolve, reject) => {
        if (!authorized) {
            reject('Unauthorized access to the user data');
        }
        resolve({
            id: id,
            username: 'admin'
        });
    });
}

try {
    getUserById(10, false)
        .then(user => console.log(user.username));
    // the following code still executes ?
    console.log('next');

} catch (error) {
    console.log(`Caught by try/catch ${error}`);
}

Surprisingly, the catch didn't work.

The theory of try/catch block is catch should be able to caught all issues from try block. If we redesign JavaScript, can we make the catch in above code to work ?

about 4 years ago · Juan Pablo Isaza
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!