V
valued customer
Is there a more concise way to do something like the the
desired code below?
The gripe is with the try-catch syntax. It takes *way* too
many lines of code to evaluate a conditional expression
when zero or more parts of the conditional expression may
trigger an error. In this case, the trigger is a call to
a non-defined (null) object.
In other words, how can you do a more simple 'try' statement
that simply spits out true or false, depending on whether
the 'tried' code threw an error or not?
Defining a function don't seem to work because you
can't pass the 'try' code as an argument. Extending the
'Global' constructor is not an option, so now what?
Any suggestions? TIA.
/// desired code (YAAY!) --------------------------------
if ( try(Meth.random) && try(Myth.random) && try(Math.random) )
{
/// do something
}
/// existing code (YUUK!) --------------------------------
var bTmp;
var bOkMeth;
try{Meth.random;
bTmp=true;}catch(e){bTmp=false;} bOkMeth = bTmp;
var bOkMyth;
try{Myth.random;
bTmp=true;}catch(e){bTmp=false;}bOkMyth = bTmp;
var bOkMath;
try{Math.random;
bTmp=true;}catch(e){bTmp=false;}bOkMath = bTmp;
if (bOkMeth && bOkMyth && bOkMath)
{
/// do something here
}
desired code below?
The gripe is with the try-catch syntax. It takes *way* too
many lines of code to evaluate a conditional expression
when zero or more parts of the conditional expression may
trigger an error. In this case, the trigger is a call to
a non-defined (null) object.
In other words, how can you do a more simple 'try' statement
that simply spits out true or false, depending on whether
the 'tried' code threw an error or not?
Defining a function don't seem to work because you
can't pass the 'try' code as an argument. Extending the
'Global' constructor is not an option, so now what?
Any suggestions? TIA.
/// desired code (YAAY!) --------------------------------
if ( try(Meth.random) && try(Myth.random) && try(Math.random) )
{
/// do something
}
/// existing code (YUUK!) --------------------------------
var bTmp;
var bOkMeth;
try{Meth.random;
bTmp=true;}catch(e){bTmp=false;} bOkMeth = bTmp;
var bOkMyth;
try{Myth.random;
bTmp=true;}catch(e){bTmp=false;}bOkMyth = bTmp;
var bOkMath;
try{Math.random;
bTmp=true;}catch(e){bTmp=false;}bOkMath = bTmp;
if (bOkMeth && bOkMyth && bOkMath)
{
/// do something here
}