exceptions for non-fatal errors JavaScript

by Mohan 2012-09-20 23:00:40


exceptions for non-fatal errors
JavaScript 1.7
function ERR() { throw ERR }
function CHK( v ) { return v || ERR() }

try {

var data1 = 'a/b/c';
var arr1 = CHK(data1).split('/');

var data2 = '';
var arr2 = CHK(data2).split('/'); // the exception is throw here

} catch(ex if ex == ERR) {

Print('non fatal error while decoding the data')
}
prints:
a b c



Tagged in:

755
like
0
dislike
0
mail
flag

You must LOGIN to add comments