I have a doubt I wrote a program and I am confused what to use to handle if any error occur in my loop and which is best practice to write to handle error handling
should I use then catch
or try catch
in my for of
loop as the output
for (value of Data){
test = await getValue(value)
.then((obj)=>{
// some code})
.catch((err)=>{
console.log(err);});
}
for (value of Data){
try{
test= await getValue(value);
}
catch (e){
console.log(e);
}
Ps: down vote welcome but need proper explanation which is best practise to write