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
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();