I have a code that I have to execute with eval()
function of JavaScript
(If you want to discuss if it is ok or not to use eval()
function please add info here: Why is using the JavaScript eval function a bad idea? but do not focus on it here).
After some code it is executed with eval()
function, and if it did not gives any exception on the try-catch
block, this code will change and I will have to execute again eval()
function in another try-catch
block.
The problems comes that if I put one try-catch
block above the other, they will be executed together and the code will not be clean, so the eval()
function it is going to be executed twice. Like this:
var code = some code here;
try{
eval(code); //Here the code has divs animations
$("#animate").promise().done(function(){
checkAnimation();
//Clear code
});
}catch(error){
console.log(error);
}
try{
eval(code); //Animations with the same div
$("#animate").promise().done(function(){
checkAnimation();
});
}catch(error){
console.log(error);
}
I also saw that there is a finally
statement but it will be executed no matter if the try-catch block have made an exception or not so it is not useful for me.
What I think
I think that I can include the second try-catch
block after clearing the code but I do not know if it would be a good practise because it is inside another function and the code inside that function can also generate an exception.
My question
Can I execute a try-catch
block only when the first try-catch
block has worked without exceptions?
EDIT: I edited my code because I forgot to put that in my second try-catch
I also had an animation.
Thanks in advance!