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

139
Views
can't get an expect console output when using async await
    function fails4() {
      return new Promise((resolve, reject) => {
        setTimeout(function () {
          reject(new Error());
        }, 100);
      });
    }

    async function myFunc4() {
      try {
        await fails4();
      } catch (e) {
        console.log(e);
        console.log('that failed', e); //<-- this gets called
      }
    }
    async function loadmYScript() {
      try {
        await myFunc4();
      } catch (error) {
        console.log(error);
        console.log(123);
      }
    }
    loadmYScript();

cant't execute the console.log(123) as I expected can anybody help me with this question very appreciated

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're calling loadmYScript, which in turn calls myFunc4, which in turn calls fails4. This last one (fails4) throws an error. The error is "catch-ed" by myFunc4. Inside this catch block you don't throw any error, there's only a couple of logs, so the result of loadmYScript is a fulfilled promise with undefined value. It is not rejected because myFunc4 doesn't throw the error.

If you throw an error inside the catch block of myFunc4, you will have your 123 logged, and the promise will be rejected.

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