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 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.
Share Improve this question edited Jun 27, 2012 at 6:45 正傑 楊 asked Jun 27, 2012 at 6:37 正傑 楊正傑 楊 1111 gold badge1 silver badge6 bronze badges 1- If these answers doesn't satisfy your needs, could you please add more information... – Beygi Commented Jun 30, 2012 at 10:55
3 Answers
Reset to default 10I 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'); }
Also you can use setTimeout if you want code from AA to be redundantly to be executed.
function AA()
{
try{
}catch(e){
return;
}
BB(); //don't execute when error happening
setTimeout("AA()",500);
}
function BB()
{
//some script
}