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

113
Views
try/catch within catch block is not executing

I have written nested try/catch block like below.

static async myEx(){
  return 'hello';
}

static async myfunc() {

try{
  Logger.info('test1');
} catch(error){
  Logger.info('test2');
  try{
    Logger.info('test3');
    return await this.myEx();
  }catch(error2){
    Logger.info('test4');
  }
}
 return null;
}

myfunc();

when I run the code,I have got following as the output.

 test2

That means second try/catch block is not executed. I want to execute myEX() function within the second try block. Can someone help me to resolve the issue?

Output that I want:

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

0

async function myEx() {
    console.log('hello');
}

async function myfunc() {
    try {
        throw new Error();
        console.log('test1');
    } catch (error) {
        console.log('test2');
        try {
            console.log('test3');
            return await myEx();
        } catch (error2) {
            console.log('test4');
        }
    }
    return null;
}

myfunc();

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!