59
rated 0 times
[
65]
[
6]
/ answers: 1 / hits: 24282
/ 9 Years ago, thu, august 13, 2015, 12:00:00
I'd like to silently break a try
- catch
in the try
block if a condition applies. ( Without throwing an unneccessary exception )
foo = function(){
var bar = Math.random() > .5;
try{
if( bar ) // Break this try, even though there is no exception here.
// This code should not execute if !!bar
alert( bar );
}
catch( e ){}
// Code that executes if !!bar
alert( true );
}
foo();
However, return
is not an option, since the function is supposed to continue executing afterwards.
UPDATE
I'd like to still keep up the opportunity to use the finally
block.
More From » operators