I need a function that stop execute javascript when catch error. For example as follow:
function AA()
{
try{
executeScript();
}catch(e){
//stop execute javascript
}
}
function executeScript()
{
throw 'error';
}
function BB()
{
//some script
}
AA();
BB(); //don't execute when error happening
Has anybody know how to do it? Thanks for help.
I think if you use a return it should be possible :)
function AA()
{
try{
}catch(e){
//stop execute javascript
return;
}
BB(); //don't execute when error happening
}
function BB()
{
//some script
}
return like that will just return undefined. You can return something more specific like a string or anything else to be able to have a convenient behaviour when you get this early return.
There are two ways,
Add return statement
function AA()
{
try{
}catch(e){
return;
}
BB();
}
function BB(){
}
If you want to return from in code before catch calls you can add throw
function AA() {
try{
javascript_abort();
}catch(e){
return;
}
BB();
}
function BB(){
}
function javascript_abort(){
throw new Error('This is not an error. This is just to abort javascript');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With