Is it possible to use throw in javascript without try..catch? As far
as I know, you must call it from within a try..catch block, or the
function that calls throw must itself be called from within try..catch,
e.g.:
function xTest(x) {
if (!x) throw 'x failed';
return 'x passed';
}
function doXTest(x){
try {
alert( xTest(x) );
} catch (e){
alert('xTest threw an error: ' + e)
}
}
doXTest(false); // -'xTest threw an error: x failed'
doXTest(true); // -'x passed'
that is, xTest() must be called from within a try..catch block because
if the test fails, throw will not be caught. Or am I missing
something?
--
Fred